local extension = Package("diy_qun")
extension.extensionName = "fox"

Fk:loadTranslationTable{
  ["diy_qun"] = "狐神包",
  ["fox"] = "狐神包",
}


local U = require "packages/utility/utility"

local lord_generals = {}
--将技能添加进池子
local insertSkill=function(skill, skills,filterfuc)
  local skill_name = skill.name
  if filterfuc(skill) then --过滤
    table.insert(skills, skill_name)
  end
end

local function pvp(room)
  for _, p in ipairs(room.players) do
    if p.id < 0 then
      return false
    end
  end
  return true
end
--从随机技能池中选择技能
---@param filterfuc @过滤函数，自定义什么函数不能过滤
---@param n @传参上限,即找多少个技能，太多有点浪费时间。下限为10
---@param m @选择技能数
---@param x @获得技能数
---@param filterfuc @过滤函数，自定义什么函数不能过滤（返回true则加入池子）
local getskillfrompool=function(player,room,filterfuc,n,m,x,prompt)
  local prompt=prompt or ("#skillpo-choose:::" .. tostring(x))
      local skill_pool, general_pool = {}, {}--技能池子
      local total=math.max(10,n)--不要遍历太多次
      local i = 0
      --此处添加技能
      local all_generals = Fk:getAllGenerals() 
      --嵌入技能-- replace Engine:getGeneralsRandomly
      for _ = 1, 999 do
        local general = table.random(all_generals)
        local skills = {}
        table.forEach(general.skills, function(s) insertSkill(s, skills,filterfuc) end)
        local skill = table.random(skills)
        if skill and not table.contains(skill_pool, skill) then
          i = i + 1
          table.insert(skill_pool, skill)
          table.insert(general_pool, general.name)

          if i == total then break end
        end
      end
      --获取table前n项
      local function getElements(tbl,n)
        local result = {}
        for i = 1, n do
            table.insert(result, tbl[i])
        end
        return result
      end
      if #skill_pool==0 then return false end
      local pskills=getElements(skill_pool,math.min(m,#skill_pool))
      local generals=getElements(general_pool,math.min(m,#general_pool))
      player.default_reply = table.random(pskills, math.min(x,#skill_pool))
      room:askForCustomDialog(player, nil,
      "packages/utility/qml/ChooseSkillBox.qml", {
        pskills, x, x, prompt,generals
      })
    local choice = player.reply_ready and json.decode(player.client_reply) or player.default_reply
    room:handleAddLoseSkills(player, table.concat(choice, "|"), nil)
    return choice

end

local selfskill=function(player,room,prompt)
  local prompt=prompt or "#playerskillpo-choose"
  local skills={}
  for _, s in ipairs(player.player_skills) do
    if not (s.attached_equip or s.name[#s.name] == "&") and not string.find(s.name, "#") then
      table.insertIfNeed(skills, s.name)
    end
  end
  
  room:askForCustomDialog(player, nil,
  "packages/utility/qml/ChooseSkillBox.qml", {
    skills, 0, #skills,  prompt
  })
  if  player.reply_ready then
    local choice = json.decode(player.client_reply) 
    return choice
  end


end

--获得未登场武将的技能
---@param room Room @ 房间
---@param player ServerPlayer @ 要询问的玩家
---@param m @选择的武将
---@param n @选择技能数
---@param expect @排除的武将
---@param filterfuc @过滤函数
local getskills=function(room,player,m,n,expect,filterfuc)
  local filterfuc=filterfuc or function(p) return false end
  local existingGenerals = {}
  --筛选
  table.forEach(room.players, function(p)
    table.insertTable(existingGenerals, {p.general, p.deputyGeneral})
  end)
  local generals = table.map(Fk:getGeneralsRandomly(10, Fk:getAllGenerals(),expect,
  (function(p) return filterfuc(p) end)), function(g) return g.name end)
  table.shuffle(generals)
  local gens = {}
  local skills = {}
  local choices = {}
  for _, general_name in ipairs(generals) do
    if #gens >= m then
      break
    end
    local general = Fk.generals[general_name]
    local g_skills = {}
    --加载技能
    for _, skill in ipairs(general.skills) do
      if  skill.permanent_skill ~= true and not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest}, skill.frequency) or skill.lordSkill)  then
        table.insertIfNeed(g_skills, skill.name)
      end
    end
    for _, s_name in ipairs(general.other_skills) do
      local skill = Fk.skills[s_name]
      if  skill.permanent_skill ~= true and not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest}, skill.frequency) or skill.lordSkill)  then
        table.insertIfNeed(g_skills, skill.name)
      end
    end
    if #g_skills > 0 then
      table.insertIfNeed(skills, g_skills)
      table.insertIfNeed(gens,general_name)
    end
    if #choices == 0 and #g_skills > 0 then
      choices = {g_skills[1]}
    end
  end
  --选择
  if #choices > 0 then
    local result = player.room:askForCustomDialog(player, "diy_getskills-choose",
    "packages/tenyear/qml/ChooseGeneralSkillsBox.qml", {
      gens, skills, 1, n, "#diy_getskills_choice:::"..n, false
    })
    if result ~= "" then
      choices = json.decode(result)
    end
    room:handleAddLoseSkills(player, table.concat(choices, "|"), nil)
  end
end

--获得未登场武将的技能
---@param room Room @ 房间
---@param player ServerPlayer @ 要询问的玩家
---@param m @选择的武将
---@param n @选择技能数
---@param expect @排除的武将
---@param filterfuc @过滤函数
local getskills2=function(room,player,target,m,n,expect,filterfuc)
  local filterfuc=filterfuc or function(p) return false end
  local existingGenerals = {}
  --筛选
  table.forEach(room.players, function(p)
    table.insertTable(existingGenerals, {p.general, p.deputyGeneral})
  end)
  local generals = table.map(Fk:getGeneralsRandomly(10, Fk:getAllGenerals(),expect,
  (function(p) return filterfuc(p) end)), function(g) return g.name end)
  table.shuffle(generals)
  local gens = {}
  local skills = {}
  local choices = {}
  for _, general_name in ipairs(generals) do
    if #gens >= m then
      break
    end
    local general = Fk.generals[general_name]
    local g_skills = {}
    --加载技能
    for _, skill in ipairs(general.skills) do
      if  skill.permanent_skill ~= true and not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest}, skill.frequency) or skill.lordSkill)  then
        table.insertIfNeed(g_skills, skill.name)
      end
    end
    for _, s_name in ipairs(general.other_skills) do
      local skill = Fk.skills[s_name]
      if  skill.permanent_skill ~= true and not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest}, skill.frequency) or skill.lordSkill)  then
        table.insertIfNeed(g_skills, skill.name)
      end
    end
    if #g_skills > 0 then
      table.insertIfNeed(skills, g_skills)
      table.insertIfNeed(gens,general_name)
    end
    if #choices == 0 and #g_skills > 0 then
      choices = {g_skills[1]}
    end
  end
  --选择
  if #choices > 0 then
    local result = player.room:askForCustomDialog(player, "diy_getskills-choose2",
    "packages/tenyear/qml/ChooseGeneralSkillsBox.qml", {
      gens, skills, 1, n, "选择至多"..n.."个技能令%src获得:"..target.id, false
    })
    if result ~= "" then
      choices = json.decode(result)
    end
    room:doIndicate(player.id,{target.id})
    room:handleAddLoseSkills(target, table.concat(choices, "|"),nil,true,true)
  end
end

Fk:loadTranslationTable{

  ["diy_getskills-choose2"]="选择武将技能",
  ["diy_getskills-choose"] = "技能选择",
  

}

local huxiangli = General(extension, "diy_qun__huxiangli", "qun",4,4)
table.insertIfNeed(lord_generals,huxiangli.name)
local huayuan = fk.CreateTriggerSkill{
  name = "diy__huayuan",
  priority = 2.1,
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self)
    elseif event == fk.Damaged then
      return target == player and player:hasSkill(self)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.GameStart then
      return true
    elseif event == fk.Damaged then
      return player.room:askForSkillInvoke(player,self.name,nil,"你可以从3个未登场的武将牌中获得其中一个技能")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local existingGenerals = {}
    --筛选
    table.forEach(room.players, function(p)
      table.insertTable(existingGenerals, {p.general, p.deputyGeneral})
    end)
    if event == fk.GameStart then
      getskills(room,player,5,2,existingGenerals,function(p) return false end)
    elseif event == fk.Damaged then
      
      getskills(room,player,3,1,existingGenerals,function(p) return false end)
    end
  end,
}

local dianhua = fk.CreateTriggerSkill{
  name = "diy__dianhua",
  events = {fk.Deathed},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    local room=player.room
    local choices={"diy_dianhua-addhp","diy_dianhua-getskill"}
    local chs = table.simpleClone(choices)
    local skills = Fk.generals[target.general]:getSkillNameList()
      if target.deputyGeneral ~= "" then
        table.insertTableIfNeed(skills, Fk.generals[target.deputyGeneral]:getSkillNameList())
      end
      skills = table.filter(skills, function(skill_name)
        local skill = Fk.skills[skill_name]
        return not skill.lordSkill and skill.permanent_skill ~= true and not table.contains({Skill.Limited, Skill.Wake, Skill.Quest}, skill.frequency) and not (#skill.attachedKingdom > 0 and not table.contains(skill.attachedKingdom, player.kingdom))
      end)
      if #skills==0 then 
        table.removeOne(chs,"diy_dianhua-getskill")
       end
    table.insert(choices, "Cancel")
    local choice = room:askForChoice(player, choices, self.name, "#diy__dianhua-ask")
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room=player.room
   local choice=self.cost_data
    if choice=="diy_dianhua-addhp" then
      if player:isWounded() then
        room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
      end
      if not player.dead then
        player:drawCards(2,self.name)
      end
    elseif choice=="diy_dianhua-getskill" then
      local skills = Fk.generals[target.general]:getSkillNameList()
      if target.deputyGeneral ~= "" then
        table.insertTableIfNeed(skills, Fk.generals[target.deputyGeneral]:getSkillNameList())
      end
      skills = table.filter(skills, function(skill_name)
        local skill = Fk.skills[skill_name]
        return not skill.lordSkill and skill.permanent_skill ~= true and not table.contains({Skill.Limited, Skill.Wake, Skill.Quest}, skill.frequency) and not (#skill.attachedKingdom > 0 and not table.contains(skill.attachedKingdom, player.kingdom))
      end)
      if #skills==0 then return end
      
      room:askForCustomDialog(player, nil,
      "packages/utility/qml/ChooseSkillBox.qml", {
        skills, 0, 1, "#diy_huanyuan-tar-choose:"..target.id 
      })
      if  player.reply_ready then
        local choice = json.decode(player.client_reply) 
        room:handleAddLoseSkills(player,table.concat(choice, "|"), nil)
      end
    end
  end,
}

local shanggqing = fk.CreateTriggerSkill{
  name = "diy_shangqing",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target and (target == player or target:isFemale()) and data.to
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player,self.name,nil,"是否发动 殇情 ，令"..Pg(target).."对"..Pg(data.to).."造成的伤害增加或减少1点，然后你受到1点伤害并摸两张牌") then
      local chocies = {"伤害+1","伤害-1"}
      local ch = player.room:askForChoice(player,chocies,self.name,nil,false)
      if ch then
        self.cost_data = ch
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if self.cost_data == "伤害+1" then
      data.damage = data.damage + 1
    elseif self.cost_data == "伤害-1" then
      data.damage = data.damage - 1
    end
    data.extra_data = data.extra_data or {} 
    data.extra_data.diy_dangqing = data.extra_data.diy_dangqing or {}
    table.insertIfNeed(data.extra_data.diy_dangqing,player.id)
  end,
  refresh_events = {fk.Damage},
  can_refresh = function (self, event, target, player, data)
    return not player.dead and data.extra_data and data.extra_data.diy_dangqing and table.contains(data.extra_data.diy_dangqing,player.id)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:damage({
      to = player,
      damage = 1,
      skillName = self.name
    })
    if not player.dead then
      player:drawCards(2,self.name)
    end
  end,
}

local shangluo = fk.CreateTriggerSkill{
  name = "diy_shangluo",
  events = {fk.RoundEnd},
  anim_type = "big",
  can_trigger = function(self, event, target, player, data)
    return player.dead and
      player:hasSkill(self,true,true)
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:revivePlayer(player,true)
    room:notifySkillInvoked(player,self.name,"support")
      if not player.dead then
        player:drawCards(3,self.name)
      end
    --room:setPlayerMark(player, "@@diy_shangluo",1)
  end,

  refresh_events = {},
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@@diy_shangluo") > 0 and player.dead
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player,"@@diy_shangluo",1)
    if player:getMark("@@diy_shangluo") == 0 then
      room:revivePlayer(player,true)
      if not player.dead then
        player:drawCards(3,self.name)
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy__huayuan"] = "化缘",
  [":diy__huayuan"] = "锁定技，<br>①游戏开始时，你从五张未登场的武将牌中选择至多两个技能获得。<br>②当你受到伤害后，你可以从三张未登场的武将牌中选择一个技能获得。",
  ["#diy_huanyuan-tar-choose"] = "选择%arg的一个非限定技获得。",
  ["diy__dianhua"] = "点化",
  [":diy__dianhua"] = "锁定技，当一名角色死亡后，你可以选择一项:<br>1.回复1点体力并摸两张牌。<br>2.获得其武将牌上一个不为限定技、觉醒技、使命技或持恒技的技能。",
  ["#diy__dianhua-ask"]="你可以选择一项:1.回复1点体力并摸两张牌；2.获得其武将牌上的一个非限定、持恒技。",
  ["diy_dianhua-addhp"]="回复1点体力并摸两张牌",  ["diy_dianhua-getskill"]="获得其武将牌上的一个非限定持恒技",
  ["diy_shangqing"] = "殇情",
  [":diy_shangqing"] = "锁定技，当你或一名女性角色造成伤害时，你可以令此伤害数值+1或-1，然后你受到1点伤害并摸两张牌。",
  ["diy_shangluo"] = "殇落",
  [":diy_shangluo"] = "持恒技，<font color='red'>此技能死亡后仍生效</font>，每轮结束时，你复活并摸3张牌。",
  ["@@diy_shangluo"] = "<font color='yellow'>殇落</font>",
  ["diy_qun__huxiangli"] = "狐湘狸",
  ["#diy_qun__huxiangli"] = "大主宰",
  ["designer:diy_qun__huxiangli"] = "狐湘狸",
  ["$diy__huayuan1"] = "裁罚者，裁罪定罚，冷锋无语。",
  ["$diy_shangqing1"] = "...刀罚血泪！"
}

-- 将技能添加到某个武将
--huayuan.permanent_skill = true
huxiangli:addSkill(huayuan)
huxiangli:addSkill(dianhua)
huxiangli:addSkill(shanggqing)
huxiangli:addSkill(shangluo)
shangluo.permanent_skill = true

local yali = fk.CreateTriggerSkill{
  name = "diy_yali",
  anim_type = "special",
  priority = 2.1,
  frequency = Skill.Compulsory,
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,table.map(room.players,Util.IdMapper))
    local players = table.simpleClone(room.players)
    table.shuffle(players)
    room.players = players
    local player_circle = {}
    for i = 1, #room.players do
      room.players[i].seat = i
      table.insert(player_circle, room.players[i].id)
    end
    for i = 1, #room.players - 1 do
      room.players[i].next = room.players[i + 1]
    end
    room.players[#room.players].next = room.players[1]
    room:doBroadcastNotify("ArrangeSeats", json.encode(player_circle))
    for _, p in ipairs(room.players) do
      if not (p.dead and p.rest <= 0) then
        room.current = p
        break
      end
    end

  end,
}
Fk:loadTranslationTable{
  ["diy_yali"] = "鸭梨",
  [":diy_yali"] = "锁定技，每轮开始时，随机分配场上座次。",
}
local xiangli = fk.CreateTriggerSkill{
  name = "diy_xiangli",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player.maxHp > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@@diy_xiangli-turn",1)
    if  player:isWounded() then
      room:recover { num = 1 - player.hp, skillName = self.name, who = player, recoverBy = player}
    end
    if player.dead then return end
    local tars = {}
    local askills = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      local skills = {}
      for _, s in ipairs(p.player_skills) do
        if s:isPlayerSkill(p) and s.visible and not player:hasSkill(s.name,true) then
          table.insert(skills, s.name)
        end
      end
      if #skills > 0 then
        table.insertIfNeed(tars,p.id)
        askills[p.id] = skills
      end
    end
    if #tars > 0 then
      local tar = room:askForChoosePlayers(player,tars,1,1,"选择一名角色获得其一个技能",self.name,true)
      if #tar > 0 then
        local gets = askills[tar[1]]
        room:askForCustomDialog(player, nil,
      "packages/utility/qml/ChooseSkillBox.qml", {
        gets, 0, 1, "#diy_xiangli-tar-choose:"..tar[1]
      })
      if  player.reply_ready then
        local choice = json.decode(player.client_reply) 
        room:handleAddLoseSkills(player,table.concat(choice, "|"), nil)
      end
      end
    end
  end,
}
local xiangli_delay = fk.CreateTriggerSkill{
  name = "#diy_xiangli_delay",
  anim_type = "defensive",
  events = {fk.DamageInflicted,fk.PreHpLost},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_xiangli-turn") > 0 
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    return true
  end,
}
xiangli:addRelatedSkill(xiangli_delay)
Fk:loadTranslationTable{
  ["diy_xiangli"] = "香梨",
  [":diy_xiangli"] = "限定技，当你进入濒死状态时，你可以将体力值回复至1点并防止本回合内受到的所有伤害与体力流失，然后你可获得场上一个技能。",
  ["@@diy_xiangli-turn"] = "香梨",
  [ "#diy_xiangli_delay"] = "香梨",

}
local cili = fk.CreateTriggerSkill{
  name = "diy_cili",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      return target == player and player:hasSkill(self) and data.card.trueName == "slash" and not data.damageDealt
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tars = {}
    local tar = player.room:getPlayerById(data.to)
    for _, p in ipairs(room.alive_players) do
      if (p:getNextAlive() == tar or tar:getNextAlive() == p) and player:canUseTo(data.card,p,{bypass_distances = true,bypass_times = true}) then
        table.insertIfNeed(tars,p.id)
      end
    end
    if #tars > 0 then
      local t = room:askForChoosePlayers(player,tars,1,1,"你可以对"..Fk:translate(tar.general).."的一名上下家继续使用"..data.card:toLogString(),self.name,true)
      if #t > 0 then
        self.cost_data = t
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      room:useCard {
        from = player.id,
        tos = table.map(self.cost_data, function(pid) return { pid } end),
        card = data.card,
        extraUse = true,
      }
    end
  end,

}
Fk:loadTranslationTable{
  ["diy_cili"] = "刺梨",
  [":diy_cili"] = "锁定技，你使用的【杀】被目标抵消后，若此【杀】未造成过伤害，你可对该目标的一名上下家使用此【杀】。",

}
local haili = fk.CreateTriggerSkill{
  name = "diy_haili",
  anim_type = "negative",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= player
  end,
  on_cost = function (self, event, target, player, data)
    local skills = {"diy__shiyong","diy__benghuai","diy__ranshang","diy__chouhai","diy__chanyuan"}
    local gets = {}
    for _, s in ipairs(skills) do
      if  not data.from:hasSkill(s,true) then
        table.insertIfNeed(gets,s)
      end 
    end
    if #gets > 0 then
      self.cost_data = table.random(gets)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{data.from.id})
    room:handleAddLoseSkills(data.from,self.cost_data)
  end,
  refresh_events = {fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player and table.contains({"diy__shiyong","diy__benghuai","diy__ranshang","diy__chouhai","diy__chanyuan"},data.name)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player,data.name,nil,false,true)
  end,
}
haili.permanent_skill = true
Fk:loadTranslationTable{
  ["diy_haili"] = "害梨",
  [":diy_haili"] = "持恒技，当你受到其他角色造成的伤害后，你令伤害来源随机获得〖恃勇〗、〖崩坏〗、〖燃殇〗、〖仇海〗或〖缠怨〗中的一个技能，<font color='red'>这些技能无法失去且死亡后仍生效</font>。",

}
local shiyong = fk.CreateTriggerSkill{
  name = "diy__shiyong",
  events = {fk.Damaged},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self,true,true) and data.card and data.card.trueName == "slash" and not data.chain
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player,-1)
  end,
}
shiyong.permanent_skill = true
Fk:loadTranslationTable{
  ["diy__shiyong"] = "恃勇",
  [":diy__shiyong"] = "持恒技，当你受到【杀】的伤害后，你失去1点体力上限。",
}
local benghuai = fk.CreateTriggerSkill{
  name = "diy__benghuai",
  anim_type = "negative",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self,true,true) and player.phase == Player.Finish and
      table.find(player.room.alive_players, function(p) return p.hp < player.hp end)
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"loseMaxHp", "loseHp"}, self.name)
    if choice == "loseMaxHp" then
      room:changeMaxHp(player, -1)
    else
      room:loseHp(player, 1, self.name)
    end
  end,
}
benghuai.permanent_skill = true
Fk:loadTranslationTable{
  ["diy__benghuai"] = "崩坏",
  [":diy__benghuai"] = "持恒技，结束阶段开始时，你选择失去1点体力值或体力上限。",
}
local ranshang = fk.CreateTriggerSkill{
  name = "diy__ranshang",
  anim_type = "negative",
  events = {fk.Damaged, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self,true,true) then
      if event == fk.Damaged then
        return data.damageType == fk.FireDamage
      else
        return player.phase == Player.Finish and player:getMark("@wutugu_ran") > 0
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      room:addPlayerMark(player, "@wutugu_ran", data.damage)
    else
      room:loseHp(player, player:getMark("@wutugu_ran"), self.name)
    end
  end,
}
ranshang.permanent_skill = true
Fk:loadTranslationTable{
  ["diy__ranshang"] = "燃殇",
  [":diy__ranshang"] = "持恒技，你受到火焰伤害时，获得一枚“燃”；结束阶段开始时，你失去“燃”点体力。",
}
local chouhai = fk.CreateTriggerSkill{
  name = "diy__chouhai",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events ={fk.DamageInflicted,fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self,true) and (event == fk.CardUsing or  player:isKongcheng()) 
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      data.damage = data.damage + 1
    else
      local dis = player.room:askForDiscard(player, 1, 1, true, self.name,true,".","仇海：弃置一张牌，或点取消受到一点伤害")
      if #dis == 0 then
        player.room:damage({
          to = player,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}
chouhai.permanent_skill = true
Fk:loadTranslationTable{
  ["diy__chouhai"] = "仇海",
  [":diy__chouhai"] = "持恒技，若你没有手牌，你受到【杀】造成的伤害+1；你使用牌时，需弃置一张牌或受到一点伤害。",
}
local chanyuan = fk.CreateInvaliditySkill {
  name = "diy__chanyuan",
  invalidity_func = function(self, from, skill)
    return from:hasSkill(self, true, true) and from.hp <= 1 and skill:isPlayerSkill(from)
  end
}
chanyuan.permanent_skill = true
Fk:loadTranslationTable{
  ["diy__chanyuan"] = "缠怨",
  [":diy__chanyuan"] = "持恒技，你体力值小于等于1时，你的其他技能失效。",
}

local huxiangli2 = General(extension, "diy_qun__shuhuxiangli", "shu",5)
table.insertIfNeed(lord_generals,huxiangli2.name)
huxiangli2:addSkill(yali)
huxiangli2:addSkill(xiangli)
huxiangli2:addSkill(cili)
huxiangli2:addSkill(haili)
huxiangli2:addRelatedSkill(shiyong)
huxiangli2:addRelatedSkill(benghuai)
huxiangli2:addRelatedSkill(ranshang)
huxiangli2:addRelatedSkill(chouhai)
huxiangli2:addRelatedSkill(chanyuan)
Fk:loadTranslationTable{
  [ "diy_qun__shuhuxiangli"] = "狐香梨",
  [ "#diy_qun__shuhuxiangli"] = "",
  ["designer:diy_qun__shuhuxiangli"] = "狐湘狸",
  ["#diy_xiangli-tar-choose"] = "选择%arg的一个技能获得。",
}

local zhanshen = fk.CreateTriggerSkill{
  name = "diy_qzhanshen",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events ={fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 or player:usedSkillTimes("diy_qfennu", Player.HistoryGame) > 0 ) 
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"斩神：是否令所有其他角色依次受到"..player:getLostHp().."点伤害并弃置其装备区的所有牌（装备区没有牌的角色改为失去1点体力）？")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,table.map(room:getOtherPlayers(player),Util.IdMapper))
    local n = player:getLostHp()
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p.dead then
        room:damage({
          from = player,
          to = p,
          damage = n,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
        if not p.dead then
          if #p:getCardIds("e") > 0 then
            room:throwCard(p:getCardIds("e"),self.name,p,player)
          else
            room:loseHp(p,1,self.name)
          end
        end
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_qzhanshen"] = "斩神",
  [":diy_qzhanshen"] = "锁定技，每回合限一次，当你受到伤害后，你可以依次对全场所有其他角色造成等同你已损失体力值点伤害并弃置其装备区内的所有牌（若该角色装备区没牌，则改为失去1点体力）。",

}
local gewan = fk.CreateTriggerSkill{
  name = "diy_gewan",
  anim_type = "negative",
  events = {fk.TargetConfirming},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetConfirming then
      return target == player and player:hasSkill(self) and (data.card.trueName == "slash" or data.card.type == Card.TypeTrick)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"是否令%src使用的"..data.card:toLogString().."对你无效，然后你立即受到两点伤害并回复1点体力:"..data.from)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      AimGroup:cancelTarget(data, player.id)
      room:damage({
        to = player,
        damage = 2,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
      if not player.dead and player:isWounded() then
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player}
      end
    end
  end
}

Fk:loadTranslationTable{
  ["diy_gewan"] = "割腕",
  [":diy_gewan"] = "锁定技，当你成为【杀】或锦囊牌的目标时，你可以令此牌对你无效，若如此做，你立即受到两点伤害并回复1点体力。",

}
local fennu = fk.CreateTriggerSkill{
  name = "diy_qfennu",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player.maxHp > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if  player:isWounded() then
      room:recover { num = player.maxHp - player.hp, skillName = self.name, who = player, recoverBy = player}
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_qfennu"] = "愤怒",
  [":diy_qfennu"] = "限定技，当你进入濒死状态时，你可以回复所有体力值，然后本局游戏你发动〖斩神〗取消次数限制。",

}
local huxiangli3 = General(extension, "diy_qun__weihuxiangli", "wei",4)
table.insertIfNeed(lord_generals,huxiangli3.name)
huxiangli3:addSkill(zhanshen)
huxiangli3:addSkill(gewan)
huxiangli3:addSkill(fennu)
Fk:loadTranslationTable{
  ["diy_qun__weihuxiangli"] = "狐相离",
  [ "#diy_qun__weihuxiangli"] = "",
  ["designer:diy_qun__weihuxiangli"] = "狐湘狸",
}

local shangjue = fk.CreateTriggerSkill{
  name = "diy_shangjue",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and #player.room.alive_players > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:askForChoosePlayers(player,table.map(room:getOtherPlayers(player),Util.IdMapper),1,1,"选择一名其他角色，其死亡时你与其交换所有身份牌和武将牌",self.name,false)
    if #tar > 0 then
      local p = room:getPlayerById(tar[1])
      local mark = p:getTableMark("@"..self.name)
      local mark2 = p:getTableMark(self.name)
      table.insertIfNeed(mark,Fk:translate(player.general))
      table.insertIfNeed(mark2,player.id)
      room:setPlayerMark(p,"@"..self.name,mark)
      room:setPlayerMark(p,self.name,mark2)
    end
  end,
  refresh_events = {fk.BeforeGameOverJudge},
  can_refresh = function (self, event, target, player, data)
    return table.contains(target:getTableMark(self.name),player.id)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room 
    if room:askForSkillInvoke(player,self.name,nil,"是否与%src交换身份牌和武将牌？:"..target.id) then
      room:doIndicate(player.id,{target.id})
      room:notifySkillInvoked(player,self.name)
      room:delay(300)
      if pvp(room) then
        local r = player.role
        player.role = target.role
        target.role = r
        player.room:notifyProperty(target, target, "role")
        player.room:notifyProperty(player, player, "role")
      end
      local g1,g2 = player.general,player.deputyGeneral
      local g3,g4 = target.general,target.deputyGeneral
      room:changeHero(player,g3,false,false,true,true)
      room:changeHero(player,g4,false,true,true,true)
      
      room:changeHero(target,g1,false,false,true,true)
      room:changeHero(target,g2,false,true,true,true)

    end
  end,
}
Fk:loadTranslationTable{
  ["diy_shangjue"] = "殇绝",
  [":diy_shangjue"] = "锁定技，游戏开始时，你令一名其他角色获得“狐”标记，然后当其死亡时，你可与其交换所有身份牌和武将牌。"..
  "<br><font color = 'grey'><small>变更身份仅限于场上不存在人机的情况。",
  ["@diy_shangjue"] = "<font color='green'>狐</font>",

}

local shanghua = fk.CreateTriggerSkill{
  name = "diy_shanghua",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and player.room.current == target and data:isPlayerSkill(target) and string.sub(data.name, 1,1) ~= "#" and  data.visible and 
      not player.tag["diy_qun"] 
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"是否令%src失去技能〖"..Fk:translate(data.name).."〗，然后你从三张武将牌中选择一个技能令其获得？:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{target.id})
    room:handleAddLoseSkills(target,"-"..data.name)
    local existingGenerals = {}
    --筛选
    table.forEach(room.players, function(p)
      table.insertTable(existingGenerals, {p.general, p.deputyGeneral})
    end)
      getskills2(room,player,target,3,1,existingGenerals,function(p) return false end)
  end,
  refresh_events = {fk.GameStart,fk.RoundStart},
  can_refresh = function (self, event, target, player, data)
    if event == fk.GameStart then
      return true
    elseif event == fk.RoundStart then
      return player.tag["diy_qun"] 
    end
  end,
  on_refresh = function (self, event, target, player, data)
    
    if event == fk.GameStart then
      player.tag["diy_qun"] = true
    elseif event == fk.RoundStart then
      player.tag["diy_qun"] = false
    end
  end,
}

Fk:loadTranslationTable{
  ["diy_shanghua"] = "殇化",
  [":diy_shanghua"] = "锁定技，当其他角色于其回合内获得一个技能后，你可令其失去此技能，然后从三张武将牌中重新选择一个技能令其获得。",

}

local huxiangli4 = General(extension, "diy_qun__wuhuxiangli", "wu",4)
table.insertIfNeed(lord_generals,huxiangli4.name)
huxiangli4:addSkill(shangjue)
huxiangli4:addSkill(shanghua)
Fk:loadTranslationTable{
  ["diy_qun__wuhuxiangli"] = "狐香慄",
  [ "#diy_qun__wuhuxiangli"] = "",
  ["designer:diy_qun__wuhuxiangli"] = "狐湘狸",
}

local huying = fk.CreateTriggerSkill{
  name = "diy_huying",
  anim_type = "special",
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player.room:getBanner("@[:]diy_hushang") 
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"是否令全场进入持续一轮的〖狐殇之吟〗环境直到本轮结束？")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:delay(500)
    room:setBanner("@[:]diy_hushang","diy_huying_yes")
    room:doBroadcastNotify("ShowToast", "已进入持续一轮的 <font color='burlywood'>狐殇之吟</font> ，持续时间内所有角色受到的伤害翻倍。")
    room:delay(500)
  end,
  refresh_events = {fk.RoundEnd,fk.Damaged,fk.Death,fk.Deathed},
  can_refresh = function (self, event, target, player, data)
    if player.room:getBanner("@[:]diy_hushang") and player.room:getBanner("@[:]diy_hushang") == "diy_huying_yes" then
      if event == fk.RoundEnd then
        return player == player.room.players[1]
      elseif event == fk.Damaged then
        return target == player
      elseif event == fk.Death then
        return target == player and player:getMark(self.name.."-round") > 0
      elseif event == fk.Deathed then
        return  target == player and player.tag[self.name] and player.tag[self.name] > 0
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room 
    if event == fk.RoundEnd then
      room:delay(500)
      room:setBanner("@[:]diy_hushang",0)
      room:doBroadcastNotify("ShowToast", "<font color='burlywood'>狐殇之吟</font>结束，受伤最多的死亡角色<font color='red'>复活</font>！")
      room:delay(500)
      local max = 0
      for _, p in ipairs(room.players) do
        p.tag[self.name] =  0
        if p.dead and p:getMark("@"..self.name.."-round") > max then
          max = p:getMark("@"..self.name.."-round")
        end
      end
      local dead = {}
      for _, p in ipairs(room.players) do
        if p:getMark("@"..self.name.."-round") == max then
          table.insertIfNeed(dead,p.id)
        end
      end
      if #dead <= 0 or max <= 0  then return end
      room:sortPlayersByAction(dead)
      for _, pid in ipairs(dead) do
        room:notifySkillInvoked(room:getPlayerById(pid),self.name,"support")
        room:setPlayerMark(player,"@"..self.name.."-round",0)
        room:revivePlayer( room:getPlayerById(pid),true)
      end
    elseif event == fk.Damaged then
      if player.dead then
        room:addPlayerMark(player,"@"..self.name.."-round",data.damage)
      else
        room:addPlayerMark(player,self.name.."-round",data.damage)
      end
    elseif event == fk.Death then
      player.tag[self.name] = player:getMark(self.name.."-round")
    elseif event == fk.Deathed then
      local n = player.tag[self.name]
      player.tag[self.name] =  0
      if player.dead then
        room:addPlayerMark(player,"@"..self.name.."-round",n)
      end
    end
  end,
}
local huying_delay = fk.CreateTriggerSkill{
  name = "#diy_huying_delay",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  priority = 0.02,
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return  player.room:getBanner("@[:]diy_hushang") and player.room:getBanner("@[:]diy_hushang") == "diy_huying_yes" and target == player 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.damage = data.damage*2
  end,
}
huying.permanent_skill = true
huying_delay.permanent_skill = true
huying:addRelatedSkill(huying_delay)
Fk:loadTranslationTable{
  ["diy_huying"] = "狐吟",
  [":diy_huying"] = "持恒技，游戏开始时，你可令全场进入持续一轮的〖狐殇之吟〗环境直到本轮结束：<br><font color='burlywood'>持续时间内，所有玩家受到的伤害翻倍，持续时间结束时累计受到伤害量最高的死亡角色复活。</font>",
  ["@diy_huying-round"] = "累计伤害",
  ["@[:]diy_hushang"] = "<font color='burlywood'>狐殇之吟</font>",
  ["diy_huying_yes"] = "吟唱中",
  [":diy_huying_yes"] = "<font color='burlywood'>持续时间内，所有玩家受到的伤害翻倍，持续时间结束时累计受到伤害量最高的死亡角色复活。</font>",
  ["#diy_huying_delay"] = "狐殇之吟",

}

local shangli = fk.CreateTriggerSkill{
  name = "diy_shangli",
  anim_type = "special",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 
  end,
  on_cost = function (self, event, target, player, data)
    local tar = player.room:askForChoosePlayers(player,table.map(player.room:getOtherPlayers(player),Util.IdMapper),1,1,"选择一名其他角色，其死亡时你复活并结束所有结算获得一个额外的回合",self.name,true)
    if #tar > 0 then
      self.cost_data = tar[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    local mark = tar:getTableMark("@"..self.name)
    local mark2 = tar:getTableMark(self.name)
    table.insertIfNeed(mark,Fk:translate(player.general))
    table.insertIfNeed(mark2,player.id)
    room:setPlayerMark(tar,"@"..self.name,mark)
    room:setPlayerMark(tar,self.name,mark2)
  end,
  refresh_events = {fk.BeforeGameOverJudge,fk.Deathed},
  can_refresh = function (self, event, target, player, data)
    if event == fk.BeforeGameOverJudge then
      return type(target:getMark(self.name)) == "table" and table.contains(target:getMark(self.name),player.id) and player.dead
    else
      return not player.dead and data.extra_data and data.extra_data.diy_shangli and table.contains(data.extra_data.diy_shangli,player.id)
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.BeforeGameOverJudge then
      room:doIndicate(target.id,{player.id})
      room:revivePlayer(player,true)
      room:notifySkillInvoked(player,self.name,"support")
      if not player.dead then
        local lord = player
  local gen
      lord.request_data = json.encode({
        path = "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml",
        data = {
          lord_generals,{"ok"}, "选择一个 狐湘狸 作为副将", false
        },
      })
      lord.default_reply = table.random(lord_generals)
      
      room:notifyMoveFocus({lord}, "选择武将")
      room:doBroadcastRequest("CustomDialog",{lord})
      for _, p in ipairs({lord}) do
        local tab =  lord_generals 
        if  p.reply_ready then
          gen = json.decode(p.client_reply).cards[1]
          
        else
          gen = p.default_reply
        end
        room:changeHero(player,gen,true,true,true,true)
        p.default_reply = ""
      end
      data.extra_data = data.extra_data or {}
      data.extra_data.diy_shangli = data.extra_data.diy_shangli or {}
      table.insertIfNeed(data.extra_data.diy_shangli,player.id)
      end
    else
      if target and target.tag["diy_huying"] and target.tag["diy_huying"] > 0 then
        local n = target.tag["diy_huying"]
        target.tag["diy_huying"] =  0
        if target.dead then
          room:addPlayerMark(target,"@diy_huying-round",n)
        end
      end
      player:gainAnExtraTurn(true)
      room.logic:breakTurn()
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_shangli"] = "殇离",
  ["@diy_shangli"] = "<font color='yellow'>狐</font>",
  [":diy_shangli"] = "限定技，当你进入濒死状态时，你可以令一名其他角色获得“狐”标记；当其死亡时，你立即复活并从其他势力的“狐湘狸”中选择一个武将作为自己的副将，然后中止当前所有角色并获得一个额外的回合。",

}
local huxiangli5 = General(extension, "diy_qun__godhuxiangli", "god",4)
huxiangli5:addSkill(huying)
huxiangli5:addSkill(shangli)
Fk:loadTranslationTable{
  ["diy_qun__godhuxiangli"] = "狐祥礼",
  [ "#diy_qun__godhuxiangli"] = "",
  ["designer:diy_qun__godhuxiangli"] = "狐湘狸",
}


local huling = fk.CreateTriggerSkill{
  name = "diy_huling",
  anim_type = "masochism",
  mute = true,
  priority = 1.1,
  events = {fk.GameStart, fk.CardUsing,fk.DamageInflicted,fk.DamageCaused,fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:getMark("@diy_huling") >= 100 then
      return false
    end

    if event == fk.GameStart then
      return true
    elseif event == fk.CardUsing then
      return target == player and data.card and data.card.type == Card.TypeBasic
    elseif event == fk.DamageInflicted or event == fk.DamageCaused then
      return target == player 
    elseif event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
              return true
            end
          end
    end
  end,
  on_cost = function (self, event, target, player, data)
      return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 0
    local anim = "masochism"
    if event == fk.GameStart then
      num = 25
    elseif event == fk.CardUsing then
      num = 10
    elseif event == fk.AfterCardsMove then
      num = 5
    else
      num = 15
    end

    room:setPlayerMark(player,"@diy_huling",math.min(player:getMark("@diy_huling") + num,100))
    room.logic:trigger("fk.diy_huling", player, { num = num})
    room:notifySkillInvoked(player,self.name,anim)
    player:broadcastSkillInvoke(self.name)
    if event == fk.PreHpLost then
      return true
    end
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill,"fk.diy_huling"},
  can_refresh = function (self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return target == player and data == self
    else
      return target == player
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
      if player:hasSkill(self) and player:getMark("@diy_huling") >= 25 then
        if not player:hasSkill("diy_hhuyun") then
          room:handleAddLoseSkills(player,"diy_hhuyun")
        end
      else
        room:handleAddLoseSkills(player,"-diy_hhuyun")
      end
      if player:hasSkill(self) and player:getMark("@diy_huling") >= 50 then
        if not player:hasSkill("diy_hhuyi") then
          room:handleAddLoseSkills(player,"diy_hhuyi")
        end
      else
        room:handleAddLoseSkills(player,"-diy_hhuyi")
      end
      if player:hasSkill(self) and player:getMark("@diy_huling") >= 75 then
        if not player:hasSkill("diy_hhunu") then
          room:handleAddLoseSkills(player,"diy_hhunu")
        end
      else
        room:handleAddLoseSkills(player,"-diy_hhunu")
      end
      if player:hasSkill(self) and player:getMark("@diy_huling") >= 100 then
        if not player:hasSkill("diy_hhushang") then
          room:handleAddLoseSkills(player,"diy_hhushang")
        end
      else
        room:handleAddLoseSkills(player,"-diy_hhushang")
      end
  end,
}
Fk:loadTranslationTable{
  ["diy_huling"] = "狐灵",
  [":diy_huling"] = "持恒技，如下情况时，你获得对应数量的狐灵：游戏开始时——25点；受到或造成伤害时——" ..
  "15点；使用基本牌时——10点；获得牌后——10点；狐灵上限为100。<br>●你根据狐灵数视为拥有以下技能：25点-〖狐运〗；50点-〖狐翼〗；75点-〖狐怒〗；" ..
  "100点-〖狐殇〗。",
  ["@diy_huling"] = "狐灵",
}

huling.permanent_skill = true

local hhuyun = fk.CreateTriggerSkill{
  name = "diy_hhuyun",
  priority = 0.91,
  mute = true,
  events = {fk.CardUsing, fk.CardResponding,fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:getMark("@@"..self.name) > 0
    end
    if target == player and player:hasSkill(self)  then
      if data.card and data.card.name == "jink" then
      local id
      if event == fk.CardUsing then
        if data.card.name == "jink" then
          if data.responseToEvent then
            id = data.responseToEvent.from  --jink
          end
        end
      elseif event == fk.CardResponding then
        if data.responseToEvent then
            id = data.responseToEvent.from 
        end
      end
      if id ~= nil then
        self.cost_data = id
        return not player.room:getPlayerById(id):isNude()
      end
      elseif data.card and table.contains({"slash","peach","analeptic"},data.card.trueName) and event == fk.CardUsing then
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return true
    elseif data.card and data.card.name == "jink" then
      return player.room:askForSkillInvoke(player,self.name, nil,"你可以获得 %dest 的一张牌::"..self.cost_data)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      
      room:notifySkillInvoked(player, self.name, "defensive")
      room:setPlayerMark(player,"@@"..self.name,0)
      return true
    elseif data.card.name == "jink" then
      local to = room:getPlayerById(self.cost_data)
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "control")
      room:doIndicate(player.id, {to.id})
      local card = room:askForCardChosen(player, to, "he", self.name)
      if card ~= nil then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      end
    elseif data.card.trueName == "slash" then
      room:notifySkillInvoked(player, self.name, "offensive")
      data.additionalDamage = (data.additionalDamage or 0) + 1
      data.disresponsiveList = table.map(room.players,Util.IdMapper)
    elseif data.card.name == "peach" then
      room:notifySkillInvoked(player, self.name, "support")
      room:changeMaxHp(player,1)
    elseif data.card.trueName == "analeptic" then
      room:notifySkillInvoked(player, self.name, "masochism")
      room:setPlayerMark(player,"@@"..self.name,1)
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_hhuyun"] = "狐运",
  [":diy_hhuyun"] = "持恒技，你打出的【闪】后，可以获得对方一张牌；使用【杀】时伤害+1且无法被响应；使用【桃】时增加1点体力上限；使用【酒】时免疫下次受到的伤害。",
  ["@@diy_hhuyun"] = "免伤",
}

hhuyun.permanent_skill = true

local hhuyi = fk.CreateTriggerSkill{
  name = "diy_hhuyi",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player.maxHp > 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"是否弃置所有“狐灵”将体力回复至1点？然后你本回合免疫所有伤害与体力流失")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@diy_huling",0)
    room.logic:trigger("fk.diy_huling", player, { num = - 100})
    room:setPlayerMark(player,"@@diy_hhuyi-turn",1)
    if  player:isWounded() then
      room:recover { num = 1 - player.hp, skillName = self.name, who = player, recoverBy = player}
    end
  end,
}
local hhuyi_delay = fk.CreateTriggerSkill{
  name = "#diy_hhuyi_delay",
  anim_type = "defensive",
  events = {fk.DamageInflicted,fk.PreHpLost},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_hhuyi-turn") > 0 
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    return true
  end,
}
hhuyi.permanent_skill = true
hhuyi_delay.permanent_skill = true
hhuyi:addRelatedSkill(hhuyi_delay)
Fk:loadTranslationTable{
  ["diy_hhuyi"] = "狐翼",
  [":diy_hhuyi"] = "持恒技，每局游戏限一次，当你进入濒死状态时，你可以弃置所有“狐灵”并将体力值回复至1点，然后防止你本回合内受到的所有伤害与体力流失。",
  ["@@diy_hhuyi-turn"] = "狐翼",
  [ "#diy_hhuyi_delay"] = "狐翼",

}

local hhunu = fk.CreateTriggerSkill{
  name = "diy_hhunu",
  anim_type = "offensive",
  events ={fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) 
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"狐怒：是否令所有其他角色依次受到"..player:getLostHp().."点伤害并弃置其装备区的所有牌（装备区没有牌的角色改为失去1点体力）？")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,table.map(room:getOtherPlayers(player),Util.IdMapper))
    local n = player:getLostHp()
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p.dead then
        room:damage({
          from = player,
          to = p,
          damage = n,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
        if not p.dead then
          if #p:getCardIds("e") > 0 then
            room:throwCard(p:getCardIds("e"),self.name,p,player)
          else
            room:loseHp(p,1,self.name)
          end
        end
      end
    end
  end,
}
hhunu.permanent_skill = true
Fk:loadTranslationTable{
  ["diy_hhunu"] = "狐怒",
  [":diy_hhunu"] = "持恒技，当你受到伤害后，你可以依次对全场所有其他角色造成等同你已损失体力值点伤害并弃置其装备区内的所有牌（若该角色装备区没牌，则改为失去1点体力）。",

}

local hhushang = fk.CreateActiveSkill{
  name = "diy_hhushang",
  anim_type = "control",
  prompt = "狐殇：你可令本局游戏所有其他玩家受到的伤害翻倍且无法回复体力值。",
  card_num = 0,
  frequency = Skill.Limited,
  target_num = 0,
  can_use = function(self, player)
    return not (Fk:currentRoom():getBanner("@[:]diy_hhushang") and Fk:currentRoom():getBanner("@[:]diy_hhushang") == "diy_hhushang_yes")
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setBanner("@[:]diy_hhushang","diy_hhushang_yes")
    room:setBanner("diy_hhushang",player.id)
  end,
}
local hhushang_delay = fk.CreateTriggerSkill{
  name = "#diy_hhushang_delay",
  anim_type = "offensive",
  mute = true,
  priority = 0.5,
  events = {fk.DamageInflicted,fk.PreHpRecover},
  can_trigger = function(self, event, target, player, data)
    return target == player and  player.room:getBanner("@[:]diy_hhushang") and player.room:getBanner("@[:]diy_hhushang") == "diy_hhushang_yes" 
    and not (player.room:getBanner("diy_hhushang") and player.room:getBanner("diy_hhushang") == player.id)
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      data.damage = data.damage * 2
    else
      player.room:notifySkillInvoked(player,self.name,"negative")
      return true
    end
  end,
}
hhushang.permanent_skill = true
hhushang_delay.permanent_skill = true
hhushang:addRelatedSkill(hhushang_delay)
Fk:loadTranslationTable{
  ["diy_hhushang"] = "狐殇",
  [":diy_hhushang"] = "持恒技，出牌阶段，你可以令本局游戏所有其他玩家受到的伤害翻倍且无法回复体力。",
  ["@[:]diy_hhushang"] = "<font color='red'>狐之吟</font>",
  ["diy_hhushang_yes"] = "已启用",
  [":diy_hhushang_yes"] = "本局游戏所有其他角色受到的伤害翻倍且无法回复体力。",
  ["#diy_hhushang_delay"] = "狐殇",
}
local hudao = fk.CreateTriggerSkill{
  name = "diy_hudao$",
  anim_type = "offensive",
  mute = true,
  events = {fk.TurnStart,fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self) and data.damageType and data.damageType == fk.ThunderDamage
    else
      return player:hasSkill(self) and target  and not target.dead
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player,self.name,"support")
      if player:isWounded() then
        room:recover({
          who = player,
          num = math.min(player:getLostHp(),data.damage),
          recoverBy = player,
          skillName = self.name
        })
      end
      return true
    else
      room:notifySkillInvoked(player,self.name,"offensive")
      room:doIndicate(player.id, {target.id})
      local judge = {
        who = target,
        reason = self.name,
        pattern = ".|.|club,spade",
      }
      room:judge(judge)
      if target.dead then return end
      if judge.card.color == Card.Black  then
        room:damage{
          to = target,
          damage = 3,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end

    end
  end,
}
hudao.permanent_skill = true
Fk:loadTranslationTable{
  ["diy_hudao"] = "狐道",
  [":diy_hudao"] = "持恒技，主公技，每个回合开始时，你令当前回合角色进行一次判定：若为黑，其受到3点无来源的雷属性伤害；你受到雷属性伤害时，改为回复等量体力。",
}
local huxiangli6 = General(extension, "diy_qun__hundunhuxiangli", "hundun",5,5,General.Female)
table.insertIfNeed(lord_generals,huxiangli6.name)
huxiangli6:addSkill(huling)
huxiangli6:addSkill(hudao)
huxiangli6:addRelatedSkill(hhuyun)
huxiangli6:addRelatedSkill(hhuyi)
huxiangli6:addRelatedSkill(hhunu)
huxiangli6:addRelatedSkill(hhushang)
Fk:loadTranslationTable{
  ["diy_qun__hundunhuxiangli"] = "狐襄灵",
  [ "#diy_qun__hundunhuxiangli"] = "",
  ["designer:diy_qun__hundunhuxiangli"] = "狐湘狸",
}



local cangfeng = fk.CreateTriggerSkill{
  name = "diy_cangfeng",
  anim_type = "defensive",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd,fk.PreHpLost,fk.BeforeMaxHpChanged,fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or target.dead then return end
    if event == fk.TurnEnd then
      return  player:hasSkill(self) and player:getMark("@"..self.name) > 0
    else
      if player.room.current  and player == player.room.current then return end
      if event == fk.PreHpLost then
        return player:hasSkill(self)
      elseif event == fk.BeforeMaxHpChanged then
        return player:hasSkill(self) and data.num < 0
      elseif event == fk.EventLoseSkill then
        return  not (data:isEquipmentSkill(player) or data.name:endsWith("&")) and data.visible and not player:hasSkill(data.name,true) and (player:hasSkill(self) or (data == self and not player:isKongcheng()))
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      local a = player:getMark("@"..self.name)
      room:notifySkillInvoked(player,self.name,"negative")
      room:setPlayerMark(player,"@"..self.name,0)
      room:damage{
        to = player,
        damage = a,
        damageType = fk.NormalDamage,
        skillName = self.name,
      }
    else
      if event == fk.PreHpLost or event == fk.BeforeMaxHpChanged  then
        if not player:isKongcheng() then
          room:notifySkillInvoked(player,self.name,"defensive")
          room:throwCard(table.random(player:getCardIds("h"),1),self.name,player,player)
          return true
        else
          room:notifySkillInvoked(player,self.name,"negative")
          room:addPlayerMark(player,"@"..self.name,1)
        end
      elseif event == fk.EventLoseSkill then
        if not player:isKongcheng() then
          room:notifySkillInvoked(player,self.name,"defensive")
          room:throwCard(table.random(player:getCardIds("h"),1),self.name,player,player)
          if not player.dead then
            room:handleAddLoseSkills(player,data.name)
          end
        else
          room:notifySkillInvoked(player,self.name,"negative")
          room:addPlayerMark(player,"@"..self.name,1)
        end
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["diy_cangfeng"] = "藏锋",
  [":diy_cangfeng"] = "锁定技，当你回合外失去体力、扣减体力上限、失去技能时，若你有手牌，随机弃置其中一张并防止之，否则获得一枚“秋”标记；回合结束时，你移除所有“秋”并受到等量点伤害。",
  ["@diy_cangfeng"] = "秋",
}

local shihe = fk.CreateViewAsSkill{
  name = "diy_shihe",
  frequency = Skill.Compulsory,
  pattern = "analeptic",
  prompt = "你可以将手中的装备牌当做【酒】使用",
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and Fk:getCardById(to_select).type == Card.TypeEquip and ((Fk.currentResponsePattern == nil and Self:canUse(Fk:cloneCard("analeptic"))) or
      (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard("analeptic"))))
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:getCardById(cards[1])
    local card = Fk:cloneCard("analeptic")
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = function(self, player)
    return player.phase == Player.NotActive
  end,
  enabled_at_response = function(self, player)
    return player.phase == Player.NotActive
  end,
}


local shihe_trig = fk.CreateTriggerSkill{
  name = "#diy_shihe_trig",
  anim_type = "drawcard",
  main_skill = shihe,
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.SkillEffect,fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(shihe.name) then return end
    if event == fk.SkillEffect then
      --[[
      local n = player.room.logic:getEventsByRule(GameEvent.SkillEffect, 2, function (e)
        local use = e.data[1]
        if use.name == data.name then
          return true
        end
    end, 0)
    return  n == 1
    ]]
      if data.visible and
      data ~= self and data ~= shihe and
      target and
      target:hasSkill(data, true, true) and
      not data:isEquipmentSkill(player) and
      not table.contains({ "m_feiyang", "m_bahu" }, data.name) and
      not table.contains(player:getTableMark(self.name), data.name) then
        local mark = player:getTableMark(self.name)
        table.insertIfNeed(mark,data.name)
        player.room:setPlayerMark(player,self.name,mark)
        return true
      end
    else
      for _, move in ipairs(data) do
        local cards = {}
        if move.to and player.id == move.to  then
          for _, info in ipairs(move.moveInfo) do
              local id = info.cardId
              if Fk:getCardById(id).type == Card.TypeEquip then
                if move.toArea == Card.PlayerEquip then
                  table.insertIfNeed(cards,id)
                end
              end
          end
          if #cards > 0 then
            self.cost_data = cards
            return true
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
      return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.SkillEffect then
      
      room:notifySkillInvoked(player,shihe.name, "drawcard")
      local card = room:getCardsFromPileByRule(".|.|.|.|.|equip")
      if #card > 0 then
        room:moveCards({
          ids = card,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = shihe.name,
        })
      end
    else
      local mark = player:getTableMark("@$diy_shihe")
      for _, cid in ipairs(self.cost_data) do
        local card = Fk:getCardById(cid)
        if not table.contains(mark,card.name) and room:askForSkillInvoke(player,self.name,nil,"史河：是否令自己永久获得"..card:toLogString().."的装备技能？") then
        room:notifySkillInvoked(player,shihe.name, "offensive")
          table.insertIfNeed(mark,card.name)
        end
      end
      room:setPlayerMark(player,"@$diy_shihe",mark)
    end
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if #player:getTableMark("@$diy_shihe") == 0 and not player.dead then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip  then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    for _, name in ipairs(player:getTableMark("@$diy_shihe")) do
      local card = Fk:cloneCard(name)
      if card.equip_skill and not player:hasSkill(card.equip_skill) then
        player.room:handleAddLoseSkills(player, card.equip_skill.name, nil, false, true)
      end
    end
  end,
}
local shihe_attackrange = fk.CreateAttackRangeSkill{
  name = "#diy_shihe_attackrange",
  correct_func = function (self, from, to)
    if #from:getTableMark("@$diy_shihe") > 0  then
      local nums = {}
      for _, name in ipairs(from:getTableMark("@$diy_shihe")) do
        if Fk:cloneCard(name).sub_type == Card.SubtypeWeapon then
          table.insert(nums, Fk:cloneCard(name).attack_range)
        end
      end
      if #nums > 0 then
        return math.max(table.unpack(nums)) - 1
      end
    end
    return 0
  end,
}
shihe:addRelatedSkill(shihe_attackrange)
shihe:addRelatedSkill(shihe_trig)

Fk:loadTranslationTable{
  ["diy_shihe"] = "史河",
  ["@$diy_shihe"] = "史河",
  ["#diy_shihe_attackrange"] = "史河",
  [ "#diy_shihe_trig"] = "史河",
  [":diy_shihe"] = "锁定技，每个技能限一次，当一个技能发动后，你从牌堆或弃牌堆中随机获得一张装备牌；你的回合外，你可以将手中的装备牌当做【酒】使用；当装备牌进入你的装备区后，你可令自己永久拥有该装备的技能。",
}

local function pg(p)
  local g1,g2 = p.general,p.deputyGeneral
  if g2 ~= nil and g2 ~= "" then
    return Fk:translate(g1).."/"..Fk:translate(g2)
  else
    return Fk:translate(g1)
  end
end
local tuigu = fk.CreateActiveSkill{
  name = "diy_tuigu",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "蜕骨：令一名未被选择过的角色重选其的一张武将牌。",
  can_use = function(self, player)
    return  true
  end,
  target_filter = function(self, to_select, selected)
    local mark = Self:getTableMark(self.name)
    return #selected == 0 and not table.contains(mark,to_select) 
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local mark = player:getTableMark(self.name)
    table.insertIfNeed(mark,to.id)
    room:setPlayerMark(player,self.name,mark)
    local deputy = false
    --[[
    local ch1 = "主将 ："..Fk:translate(to.general)
    local ch2 = "副将 ："..Fk:translate(to.deputyGeneral)
    local chs = {ch1}
    if to.deputyGeneral ~= "" then
      table.insert(chs,ch2)
    end
    local choice = room:askForChoice(player,chs,self.name,"选择需要令"..pg(to).."更换的武将牌",false,{ch1,ch2})
    ]]
    local gens = {to.general}
    if to.deputyGeneral ~= "" then
      table.insert(gens,2,to.deputyGeneral)
    end
  local gen
      local result = player.room:askForCustomDialog(player, self.name,
      "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
        gens,
        {"OK"},
        "选择"..pg(to).."的一张武将牌令其重选", false
      })
      if result ~= "" then
        local reply = json.decode(result)
        gen = reply.cards[1]
      end
      if gen == nil then
        gen = table.random(gens)
      end
      if #gens > 1 and gens[1] ~= gen then
        deputy = true
      end
      room:doBroadcastNotify("ShowToast", "<font color='burlywood'>"..pg(to).."</font> 重新选一个"..(deputy == true  and "副将" or "主将"))
    local tgen = room:askForGeneral(to,room:getNGenerals(room.settings.generalNum),1,false)
    room:changeHero(to,tgen,false,deputy,true,true)
  end,
}
local tuigu_trig = fk.CreateTriggerSkill{
  name = "#diy_tuigu_trig",
  main_skill = tuigu,
  anim_type = "control",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(tuigu.name) then return end
    return not table.contains(player:getTableMark(tuigu.name),target.id)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"蜕骨：是否令"..pg(target).."重选一张武将牌？")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = target
    local mark = player:getTableMark("diy_tuigu")
    table.insertIfNeed(mark,to.id)
    room:setPlayerMark(player,"diy_tuigu",mark)
    local deputy = false
    --[[
    local ch1 = "主将 ："..Fk:translate(to.general)
    local ch2 = "副将 ："..Fk:translate(to.deputyGeneral)
    local chs = {ch1}
    if to.deputyGeneral ~= "" then
      table.insert(chs,ch2)
    end
    local choice = room:askForChoice(player,chs,self.name,"选择需要令"..pg(to).."更换的武将牌",false,{ch1,ch2})
    ]]
    local gens = {to.general}
    if to.deputyGeneral ~= "" then
      table.insert(gens,2,to.deputyGeneral)
    end
  local gen
      local result = player.room:askForCustomDialog(player, self.name,
      "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
        gens,
        {"OK"},
        "选择"..pg(to).."的一张武将牌令其重选", false
      })
      if result ~= "" then
        local reply = json.decode(result)
        gen = reply.cards[1]
      end
      if gen == nil then
        gen = table.random(gens)
      end
      if #gens > 1 and gens[1] ~= gen then
        deputy = true
      end
      room:doBroadcastNotify("ShowToast", "<font color='burlywood'>"..pg(to).."</font> 重新选一个"..(deputy == true  and "副将" or "主将"))
    local tgen = room:askForGeneral(to,room:getNGenerals(room.settings.generalNum),1,false)
    room:changeHero(to,tgen,false,deputy,true,true)
  end,
}
tuigu:addRelatedSkill(tuigu_trig)

Fk:loadTranslationTable{
  ["diy_tuigu"] = "蜕骨",
  [ "#diy_tuigu_trig"] = "蜕骨",
  [":diy_tuigu"] = "每名角色限一次，出牌阶段/当一名角色进入濒死状态时，你可 令一名角色/令其 重选一张武将牌。",
}

local huxiangli7 = General(extension, "diy_qun__jinhuxiangli", "jin",4,4,General.Female)
table.insertIfNeed(lord_generals,huxiangli7.name)
huxiangli7:addSkill(cangfeng)
huxiangli7:addSkill(shihe)
huxiangli7:addSkill(tuigu)
Fk:loadTranslationTable{
  ["diy_qun__jinhuxiangli"] = "狐春秋",
  [ "#diy_qun__jinhuxiangli"] = "",
  ["designer:diy_qun__jinhuxiangli"] = "狐湘狸",
}

local hhufu = fk.CreateTriggerSkill{
  name = "diy_hhufu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged,fk.EventAcquireSkill,fk.EventLoseSkill,fk.CardUsing,fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      return target == player and (target:getMark("@diy_hhufu1") > 0 or target:getMark("@diy_hhufu2") > 0 and target:getMark("@diy_hhufu3") > 0 )
    end
    if not player:hasSkill(self) or target == player or target.dead then return end
    if event == fk.HpChanged then
      return true
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return player.room:getTag("RoundCount")  and player.room:getTag("RoundCount") > 0 and not player.tag["diy_qun"] and not (data:isEquipmentSkill(player) or data.name:endsWith("&")) and data.visible and (event == fk.EventAcquireSkill or not target:hasSkill(data.name,true,true))
    elseif event == fk.CardUsing or event == fk.CardResponding then
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      local n = target:getMark("@diy_hhufu1") + target:getMark("@diy_hhufu2") + target:getMark("@diy_hhufu3")
      room:notifySkillInvoked(player,self.name,"drawcard")
      room:setPlayerMark(player,"@diy_hhufu1",0)
      room:setPlayerMark(player,"@diy_hhufu2",0)
      room:setPlayerMark(player,"@diy_hhufu3",0)
      player:drawCards(n,self.name)
    else
      room:doIndicate(player.id,{target.id})
      room:notifySkillInvoked(player,self.name,"special")
      if event == fk.HpChanged then
        room:addPlayerMark(target,"@diy_hhufu1",1)
      elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
        room:addPlayerMark(target,"@diy_hhufu2",1)
      elseif event == fk.CardUsing or event == fk.CardResponding then
        room:addPlayerMark(target,"@diy_hhufu3",1)
      end
    end
  end,
  refresh_events = {fk.TurnEnd,fk.DamageInflicted,fk.Damage,fk.GameStart,fk.RoundStart},
  can_refresh = function (self, event, target, player, data)
    if event == fk.GameStart then
      return true
    elseif event == fk.RoundStart then
      return player.tag["diy_qun"]
    end
    if event == fk.TurnEnd then
      return target == player and (target:getMark("@diy_hhufu1") > 0 or target:getMark("@diy_hhufu2") > 0 and target:getMark("@diy_hhufu3") > 0 )
    else
      return target == player and player:getMark("@diy_hhufu1") > 0
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      player.tag["diy_qun"] = true
    elseif event == fk.RoundStart then
      player.tag["diy_qun"] = false
    end
    if event == fk.TurnEnd then
      local n = target:getMark("@diy_hhufu1") + target:getMark("@diy_hhufu2") + target:getMark("@diy_hhufu3")
      room:notifySkillInvoked(player,self.name,"drawcard")
      room:setPlayerMark(player,"@diy_hhufu1",0)
      room:setPlayerMark(player,"@diy_hhufu2",0)
      room:setPlayerMark(player,"@diy_hhufu3",0)
      player:drawCards(n,self.name)
    elseif event == fk.DamageInflicted then
      data.damage = data.damage + player:getMark("@diy_hhufu1")
      room:notifySkillInvoked(player,self.name,"negative")
    elseif event == fk.Damage then
      if not player.dead then
        room:notifySkillInvoked(player,self.name,"negative")
        room:loseHp(player,1,self.name)
      end
    end
  end,
}
local hhufu_in = fk.CreateInvaliditySkill {
  name = "#diy_hhufu_in",
  invalidity_func = function(self, from, skill)
    return from:getMark("@diy_hhufu2") > 0  and skill:isPlayerSkill(from)
  end
}
local hhufu_max = fk.CreateMaxCardsSkill{
  name = "#diy_hhufu_max",
  frequency = Skill.Compulsory,
  correct_func = function(self, player)
      return - player:getMark("@diy_hhufu3")
  end,
}
hhufu:addRelatedSkill(hhufu_in)
hhufu:addRelatedSkill(hhufu_max)
Fk:loadTranslationTable{
  ["diy_hhufu"] = "狐符",
  ["#diy_hhufu_in"] = "狐符",
  ["#diy_hhufu_max"] = "狐符",
  [":diy_hhufu"] = "锁定技，当其他角色 体力值发生变化时，你令其获得一枚“<font color='red'>体符</font>”；失去/获得技能后，你令其获得一枚“<font color='burlywood'>气符</font>”；使用/打出手牌时，令其获得一枚“<font color='blue'>破符</font>”；有“符”的玩家回合结束时移除所有“符”并摸等量张牌。"..
  "<br>①<font color='red'>体符</font>：受到的伤害+X，且造成伤害后失去一点体力。"..
  "<br>②<font color='burlywood'>气符</font>：所有技能失效。"..
  "<br>③<font color='blue'>破符</font>：手牌上限-X。"..
  "（X为对应“符”标记数）",
  ["@diy_hhufu1"] = "<font color='red'>体符</font>",
  ["@diy_hhufu2"] = "<font color='burlywood'>气符</font>",
  ["@diy_hhufu3"] = "<font color='blue'>破符</font>",
}
local hhupai = fk.CreateTriggerSkill{
  name = "diy_hhupai",
  anim_type = "special",
  events = {fk.GameStart,fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.GameStart then
      local tars = {}
      for _, p in ipairs(player.room.players) do
        if not p:hasSkill(self,true,true) then
          table.insertIfNeed(tars,p.id)
        end
      end
      if #tars > 0 then
        self.cost_data = tars
        return true
      end
    elseif event == fk.CardUsing then
      if target ~= player then return end
      player.room:addPlayerMark(player,"@"..self.name,1)
      if player:getMark("@"..self.name) >= 5 then
        player.room:setPlayerMark(player,"@"..self.name,0)
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      room:doIndicate(player.id,self.cost_data)
      for _, pid in ipairs(self.cost_data) do
        local p = room:getPlayerById(pid)
        if not p:hasSkill(self,true,true) then
          room:handleAddLoseSkills(p,self.name,nil)
        end
      end
    else
      local card1 = room:getNCards(1)
      player:showCards(card1)
      if player.dead  then return end
      local suit = {Fk:getCardById(card1[1]).suit}
      local cards = {card1[1]}
      room:setCardEmotion(card1[1],"judgegood")
      room:delay(500)
      room:moveCardTo(cards,Card.DiscardPile,nil,fk.ReasonJustMove,self.name,"",false)
      if table.contains(suit,Card.Heart) then
        if not player.dead then
          room:changeMaxHp(player,1)
          if not player.dead then
            room:recover({
            who = player,
            num = player:getLostHp(),
            skillName = self.name
          })
          end
        end
        room:delay(500)
      end
      if table.contains(suit,Card.Diamond) then
        local to = table.random(room.alive_players)
        if to == player then return end
        room:swapSeat(player, to)
        if room.current and room.current == player and not player:insideExtraTurn() then
          room:setBanner("diy_hhupai_turn",{player.id,to.id,})
        end
        if not player.dead then
          player:gainAnExtraTurn(true)
        end
        room:delay(500)
      end
      if table.contains(suit,Card.Club) then
        room:changeMaxHp(player,-1)
        if not player.dead then
          room:loseHp(player,1,self.name)
        end
        room:delay(500)
      end
      if table.contains(suit,Card.Spade) then
        local ds = room.tag[self.name] or {}
        room.tag[self.name] = {player.id}
        room:killPlayer({who = player.id})
        room:delay(500)
        if #ds > 0 then
          room:delay(500)
          local n = room:getPlayerById(ds[1])
          if n.dead then
            room:notifySkillInvoked(n,self.name,"support")
            room:revivePlayer(n,true)
          end
        end
      end
    end
  end,
  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return player.room:getBanner("diy_hhupai_turn") and type(player.room:getBanner("diy_hhupai_turn")) == "table" 
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if room:getBanner("diy_hhupai_turn") and type(room:getBanner("diy_hhupai_turn")) == "table" and room.current and room:getBanner("diy_hhupai_turn")[1] == room.current.id then
      room.current = room:getPlayerById(room:getBanner("diy_hhupai_turn")[2])
    end
    room:setBanner("diy_hhupai_turn",nil)
  end,
}
Fk:loadTranslationTable{
  ["diy_hhupai"] = "狐牌",
  ["@diy_hhupai"] = "狐牌",
  [":diy_hhupai"] = "游戏开始时，令全场玩家获得此技能；<br>当一名角色累计使用5张牌时，其展示牌堆顶的一张牌，若这张牌的花色为："..
  "<br><font color='red'>♥</font>，其增加一点体力上限并回复所有体力值。"..
  "<br><font color='red'>♦</font>，其与场上一名随机角色交换位置并于此回合结束后执行一个额外的回合。"..
  "<br>♣，其减少一点体力上限并失去一点体力。"..
  "<br>♠，其死亡，本局游戏下次触发此效果后其复活",
}

local huxiangli8 = General(extension, "diy_qun__quehuxiangli", "que",4)
table.insertIfNeed(lord_generals,huxiangli8.name)
huxiangli8:addSkill(hhufu)
huxiangli8:addSkill(hhupai)
Fk:loadTranslationTable{
  ["diy_qun__quehuxiangli"] = "狐道长",
  [ "#diy_qun__quehuxiangli"] = "",
  ["designer:diy_qun__quehuxiangli"] = "狐湘狸",
}

local husi = fk.CreateTriggerSkill{
  name = "diy_husi",
  anim_type = "negative",
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,table.map(room.alive_players,Util.IdMapper))
    for _, p in ipairs(room.alive_players) do
      local eqipSlots = p:getAvailableEquipSlots()
      if not table.contains(p.sealedSlots, Player.JudgeSlot) then
        table.insert(eqipSlots, Player.JudgeSlot)
      end
      player.room:abortPlayerArea(p, eqipSlots)
    end
  end,
  refresh_events = {fk.AreaResumed},
  can_refresh = function (self, event, target, player, data)
    return target == player
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:notifySkillInvoked(player,self.name)
    player.room:abortPlayerArea(player, data.slots)
  end,
}
local husi_mod = fk.CreateTargetModSkill{
  name = "#diy_husi_mod",
  bypass_times = function(self, player, skill, scope)
    return true
  end,
  bypass_distances = function(self, player, skill, scope)
    return true
  end,
}
husi:addRelatedSkill(husi_mod)
Fk:loadTranslationTable{
  ["diy_husi"] = "狐肆",
  [":diy_husi"] = "①游戏开始时，你永久废除场上所有玩家的装备区与判定区；<br>②本局游戏所有玩家使用牌无距离次数限制。",
  ["#diy_husi_mod"] = "狐肆",
}

local huwei = fk.CreateTriggerSkill{
  name = "diy_huwei",
  anim_type = "negative",
  events = {fk.TurnStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{target.id})
    local card = room:askForDiscard(target,1,1,true,self.name,true,".|.|.|.|.|equip","弃置一张装备牌，或随机一个技能本回合失效")
    if target.dead then return end
    if #card > 0 then
    else
      local mark = target:getTableMark("@diy_huwei-turn")
      local skills = {}
      for _, s in ipairs(target.player_skills) do
        if s.visible and not s.name:startsWith("#") and not s.name:endsWith("&") and s.permanent_skill ~= true and not s:isEquipmentSkill(target) then
          table.insertIfNeed(skills,s.name)
        end
      end
      if #skills > 0 then
        table.insertIfNeed(mark,table.random(skills))
        room:setPlayerMark(target,"@diy_huwei-turn",mark)
      end
    end
  end,
}
local huwei_invalidity = fk.CreateInvaliditySkill {
  name = "#diy_huwei_invalidity",
  frequency = Skill.Compulsory,
  invalidity_func = function(self, from, skill)
    return table.contains(from:getTableMark("@diy_huwei-turn"),skill.name)
  end
}
huwei:addRelatedSkill(huwei_invalidity)
Fk:loadTranslationTable{
  ["diy_huwei"] = "狐威",
  [":diy_huwei"] = "锁定技，其他角色于其回合开始时需弃置一张装备牌，否则本回合其随机一个技能失效。",
  ["#diy_huwei_invalidity"] = "狐威",
  ["@diy_huwei-turn"] = '技能失效',
}

local huluan = fk.CreateActiveSkill{
  name = "diy_huluan",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  prompt = "狐乱：你可令场上所有玩家依次随机使用其手牌中的所有【杀】。",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:doIndicate(player.id,table.map(room.alive_players,Util.IdMapper))
    local all = table.map(room.alive_players,Util.IdMapper)
    room:sortPlayersByAction(all)
    for _, pid in ipairs(all) do
      local p =  room:getPlayerById(pid)
      if not p.dead and not p:isKongcheng() then
        local can = true
        while can and not p.dead do
          can = false
          for _, cid in ipairs(p:getCardIds("h")) do
            if  Fk:getCardById(cid).trueName == "slash" and room:getCardOwner(cid) == p and room:getCardArea(cid) == Card.PlayerHand then
              local tars = {}
              for _, p2 in ipairs(room:getOtherPlayers(p)) do
                if p:canUseTo(Fk:getCardById(cid),p2,{bypass_distances = true,bypass_times = true}) then
                  table.insertIfNeed(tars,p2.id)
                end
              end
              if #tars > 0 then
                can = true
                room:useCard({
                from = p.id,
                tos = {{table.random(tars)}},
                card = Fk:getCardById(cid),
                extraUse = true,
                })
                room:delay(500)
                break
              end
            end
          end
        end
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_huluan"] = "狐乱",
  [":diy_huluan"] = "锁定技，出牌阶段限一次，你可令场上所有玩家依次随机使用其手牌中的所有【杀】。",
}

local huyuan = fk.CreateTriggerSkill{
  name = "diy_huyuan$",
  anim_type = "support",
  frequency =  Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tars = table.map(room:getOtherPlayers(player),Util.IdMapper)
    room:sortPlayersByAction(tars)
    room:doIndicate(player.id,tars)
    for _, pid in ipairs(tars) do
      local p = room:getPlayerById(pid)
      if not p.dead then
        local card = room:askForCard(p,1,1,true,self.name,true,".","交给"..pg(player).."一张牌或失去一点体力，若给出了【桃】、【酒】则你额外增加一点体力上限和体力")
        if #card > 0 then
          room:obtainCard(player,card,true,fk.ReasonGive,p.id,self.name)
          if not p.dead and table.contains({"peach","analeptic"},Fk:getCardById(card[1]).name) then
            room:changeMaxHp(p,1) 
            if not p.dead and p:isWounded() then
              room:recover({
                who = p,
                num = 1,
                recoverBy = player,
                skillName = self.name
              })
            end
          end
        else
          room:loseHp(p,1,self.name)
        end
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_huyuan"] = "狐援",
  [":diy_huyuan"] = "主公技，限定技，当你进入濒死状态时，其他角色需交给你一张牌或失去一点体力，若其交出了【桃】或【酒】，其增加一点体力上限并回复一点体力值。",
}
local huxiangli9 = General(extension, "diy_qun__zhixuhuxiangli", "zhixu",4)
table.insertIfNeed(lord_generals,huxiangli9.name)
huxiangli9:addSkill(husi)
huxiangli9:addSkill(huwei)
huxiangli9:addSkill(huluan)
huxiangli9:addSkill(huyuan)
Fk:loadTranslationTable{
  ["zhixu"] = "秩序",
  ["diy_qun__zhixuhuxiangli"] = "狐九渊",
  [ "#diy_qun__zhixuhuxiangli"] = "",
  ["designer:diy_qun__zhixuhuxiangli"] = "狐湘狸",
}



----以下是伪.废除手牌区
---
local function abortPlayerHand(player)
  local self = player.room
  local cardsToDrop = {}
  local slotsSealed = {}
  local slotsToSeal = {}
  if not table.contains(player.sealedSlots, "Player.HandSlot") then
    table.insertIfNeed(slotsToSeal,"Player.HandSlot")

    local handCards = player:getCardIds(Player.Hand)
    if #handCards > 0 then
      table.insertTable(cardsToDrop,handCards)
    end
  end

  if #slotsToSeal == 0 then
    return
  end

  self:moveCards({
    ids = cardsToDrop,
    from = player.id,
    toArea = Card.DiscardPile,
    moveReason = fk.ReasonPutIntoDiscardPile,
  })

  table.insertTable(player.sealedSlots, slotsToSeal)
  self:setPlayerMark(player,"@@diy_handslot",1)

  for _, s in ipairs(slotsToSeal) do
    self:sendLog{
      type = "#AbortArea",
      from = player.id,
      arg = s,
    }
  end
  self.logic:trigger(fk.AreaAborted, player, { slots = slotsSealed })
end
Fk:loadTranslationTable{
  ["Player.HandSlot"] = "手牌区",
  ["@@diy_handslot"] = "<b>废除手牌区</b>",
  ["diy_removehand"] = "废除手牌区",
}
local removehand = fk.CreateTriggerSkill{
  name = "diy_removehand",
  mute = true,
  global = true,
  --frequency = Skill.Compulsory,
  refresh_events = {fk.BeforeCardsMove,fk.AfterDrawInitialCards,fk.AfterPlayerRevived},
  can_refresh = function(self, event, target, player, data)
    if table.contains(player.sealedSlots,"Player.HandSlot") then
      if  event == fk.BeforeCardsMove then
        for _, move in ipairs(data) do
          if move.to == player.id and table.contains({Player.Hand},move.toArea)then
            return true
          end
        end
      elseif event == fk.AfterDrawInitialCards then
        return target == player and #player:getCardIds("h") > 0
      elseif event == fk.AfterPlayerRevived then
          return target == player 
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if  event == fk.BeforeCardsMove then
      local cards = {}
      if player:hasSkill("diy_hushi") then
        return false
      else
        for _, move in ipairs(data) do
          if move.to == player.id and table.contains({Player.Hand},move.toArea) then
            move.toArea = Card.DiscardPile
            move.moveVisible = true
            move.to = nil
          end
        end
      end
    elseif event == fk.AfterDrawInitialCards then
      local cardIds = player:getCardIds(Player.Hand)
      player:removeCards(Player.Hand, cardIds)
      table.insertTable(room.discard_pile, cardIds)
      for _, id in ipairs(cardIds) do
        Fk:filterCard(id, nil)
      end
      local move_to_notify = {}   ---@type CardsMoveStruct
      move_to_notify.from = player.id
      move_to_notify.toArea = Card.DiscardPile
      move_to_notify.moveInfo = {}
      move_to_notify.moveReason = fk.ReasonJustMove
      for _, id in ipairs(cardIds) do
        table.insert(move_to_notify.moveInfo,
        { cardId = id, fromArea = Card.PlayerHand })
      end
      room:notifyMoveCards(nil, {move_to_notify})
      for _, id in ipairs(cardIds) do
        room:setCardArea(id, Card.DiscardPile, nil)
      end
    elseif event == fk.AfterPlayerRevived then
        room:setPlayerMark(player,"@@diy_handslot",1)
    end
  end,
}
Fk:addSkill(removehand)
----以上是伪.废除手牌区
---
local hushi = fk.CreateViewAsSkill{
  name = "diy_hushi",
  pattern = ".",
  interaction = function()
    local choices = {}
    if #Self:getTableMark("diy_hushi") > 1  then
      for _, cid in ipairs(Self:getTableMark("diy_hushi")) do
        local card = Fk:getCardById(cid)
        if card:getMark("@@diy_hushi") == 0 and not table.contains(choices,card.name) and ((Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
            table.insertIfNeed(choices, card.name)
        end
      end
    end
    return UI.ComboBox {choices = choices}
  end,
  view_as = function(self, cards)
    if self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local tars = {}
    for _, p in ipairs(room.alive_players) do
      for _, cid in ipairs(p:getCardIds("h")) do
        local card = Fk:getCardById(cid)
        if card:getMark("@@diy_hushi") == 0 and card.name == use.card.name  then
          table.insertIfNeed(tars,p.id)
          break
        end
      end
    end
    if #tars <= 0 then return end
    local tar
    if #tars > 1 then
      tar = room:askForChoosePlayers(player,tars,1,1,"选择使用谁手牌中的【"..Fk:translate(use.card.name).."】？",self.name,false)
    else
      tar = tars
    end
    if #tar == 0 then 
      tar = table.random(tars,1)
    end
    local p = room:getPlayerById(tar[1])
    local cards = {}
    for _, cid in ipairs(p:getCardIds("h")) do
      local card = Fk:getCardById(cid)
      if card:getMark("@@diy_hushi") == 0 and card.name == use.card.name   then
          table.insertIfNeed(cards,cid)
      end
    end
    if #cards == 0 then return end
    local get,_
    if #cards > 1 then
      get, _ = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "从 "..pg(p).." 的手牌中选择一张使用或打出", nil, 1, 1, p:getCardIds("h"))
    else
      get = cards
    end
    if #get == 0 then 
      get = table.random(cards,1)
     end
    use.card:addSubcard(Fk:getCardById(get[1]))
    return
  end,
  enabled_at_play = function(self, player)
    local mark = player:getTableMark("diy_hushi")
    for _, cid in ipairs(mark) do
      local to_use = Fk:getCardById(cid)
      to_use.skillName = self.name
      if to_use:getMark("@@diy_hushi") == 0 and player:canUse(to_use) and not player:prohibitUse(to_use) then
        return true
      end
    end
    return false
  end,
  enabled_at_response = function(self, player, response)
    local mark = player:getTableMark("diy_hushi")
    if not response then
      for _, cid in ipairs(mark) do
        local to_use = Fk:getCardById(cid)
        to_use.skillName = self.name
        if to_use:getMark("@@diy_hushi") == 0 and Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use) and
            not player:prohibitUse(to_use)  then
          return true
        end
      end
    else
      for _, cid in ipairs(mark) do
        local to_use = Fk:getCardById(cid)
        to_use.skillName = self.name
        if to_use:getMark("@@diy_hushi") == 0 and Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use)  then
          return true
        end
      end
    end
    return false
  end,
}
local hushi_trigger = fk.CreateTriggerSkill{
  name = "#diy_hushi_trigger",
  refresh_events = {fk.AfterCardsMove,fk.AfterPlayerRevived,fk.GameStart,"fk.Aftershouqi",fk.EventAcquireSkill,fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      return target == player and data == self and not player:hasSkill(hushi.name,true)
    end
    if event == fk.AfterCardsMove then
      if player ~= player.room.players[1] then return end
        for _, move in ipairs(data) do
          if move.toArea == Card.PlayerHand then
            return true
          end
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
    elseif table.contains({fk.GameStart,"fk.Aftershouqi"},event) then
      return player == player.room.players[1]
    end
    if not player:hasSkill(self.name,true) then return false end
    if event == fk.AfterPlayerRevived then
      return target == player
    elseif event == fk.EventAcquireSkill then
      return target == player and data == self
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventLoseSkill then
      room:setPlayerMark(player,"diy_hushi",0)
      return false
    end
    if not room.tag["diy_hushi"] or table.contains({fk.AfterCardsMove,fk.GameStart,"fk.Aftershouqi"},event) then
      local cards = {}
      for _, p in ipairs(room.players) do
        if #p:getCardIds("h") > 0 then
          table.insertTableIfNeed(cards,p:getCardIds("h"))
        end
      end
      room.tag["diy_hushi"] = cards
      for _, p in ipairs(room.alive_players) do
        if p:hasSkill("diy_hushi",true) then
          room:setPlayerMark(p,"diy_hushi",room.tag["diy_hushi"] )
        else
          room:setPlayerMark(p,"diy_hushi",0)
        end
      end
      return false
    end
    room:setPlayerMark(player,"diy_hushi",room.tag["diy_hushi"] )
  end,
}
local hushi_filter = fk.CreateFilterSkill{
  name = "#diy_hushi_filter",
  frequency = Skill.Compulsory,
  card_filter = function(self, to_select, player)
    return  to_select:getMark("@@diy_hushi") > 0
  end,
  view_as = function(self, to_select)
    local card = Fk:cloneCard("es__poison",to_select.suit, to_select.number)
    card.skillName = self.name
    return card
  end,
}
local hushi_delay = fk.CreateTriggerSkill{
  name = "#diy_hushi_delay",
  anim_type = "special",
  events = {fk.GameStart,fk.HpLost,fk.BeforeCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.GameStart then 
      return  player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    elseif event == fk.HpLost then
      return target ~= player and data.skillName and table.contains({"poison","es__poison"},data.skillName)
    elseif event == fk.BeforeCardsMove then
      for _, move in ipairs(data) do
        if move.to == player.id and table.contains({Player.Hand},move.toArea)  then
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then 
      abortPlayerHand(player)
    elseif event == fk.HpLost then
      room:changeMaxHp(player,1)
      if not player.dead and player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = hushi.name
        })
      end
    elseif event == fk.BeforeCardsMove then
      local cards = {}
      for _, move in ipairs(data) do
        if move.to == player.id and table.contains({Player.Hand,Player.Equip,Player.Judge},move.toArea) then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(cards,info.cardId)
          end
          move.to = nil
          move.moveInfo = {}
        end
      end
      if #cards <= 0 then return end
      local moves = {}
        local m = #room:getOtherPlayers(player)
        local all = table.simpleClone(table.map(room:getOtherPlayers(player),Util.IdMapper))
        room:sortPlayersByAction(all)
      for k, pid in pairs(all) do
        local p = room:getPlayerById(pid)
        if not p.dead and not p:hasSkill(self) then
        local n = 0
        if k == m then
          n = #cards
        else
          n = math.random(0,#cards)
        end
        if n > 0 then
          local ids = {}
          local cards2 = table.random(cards,n)
          for _, cid in ipairs(cards2) do
            table.removeOne(cards,cid)
            table.insertIfNeed(ids,cid)
          end
          room:doIndicate(player.id,{pid})
          room:moveCardTo(ids,Card.PlayerHand,p,fk.ReasonGive,self.name,"",false,player.id,"@@diy_hushi")
        end
        end
      end
      if #cards > 0 then
        room:moveCardTo(cards,Card.DiscardPile,nil,fk.ReasonJustMove,self.name,"",true,player.id)
      end
    end
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId):getMark("@@diy_hushi") > 0 then
              return true
            end
          end
        end
      end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId):getMark("@@diy_hushi") > 0 then
              room:setCardMark(Fk:getCardById(info.cardId),"@@diy_hushi",0)
            end
          end
        end
      end
  end,
}
local hushi_visib = fk.CreateVisibilitySkill{
  name = '#diy_hushi_visib',
  frequency = Skill.Compulsory,
  card_visible = function(self, player, card)
    if player:hasSkill(hushi) and Fk:currentRoom():getCardArea(card) == Card.PlayerHand then
      return true
    end
  end
}
hushi_visib.permanent_skill = true
hushi_delay.permanent_skill = true
hushi_filter.permanent_skill = true
hushi_trigger.permanent_skill = true
hushi.permanent_skill = true
hushi:addRelatedSkill(hushi_delay)
hushi:addRelatedSkill(hushi_filter)
hushi:addRelatedSkill(hushi_trigger)
hushi:addRelatedSkill(hushi_visib)
Fk:loadTranslationTable{
  ["diy_hushi"] = "狐视",
  ["#diy_hushi_trigger"] = "狐视",
  ["#diy_hushi_filter"] = "狐视",
  ["#diy_hushi_delay"] = "狐视",
  ["#diy_hushi_visib"] = "狐视",
  ["@@diy_hushi"] = "毒",
  [":diy_hushi"] = "持恒技，<br>①游戏开始时，废除你的手牌区；<br>②其他玩家手牌于你可见，且你可将其他玩家的手牌正常使用或打出；<br>③你即将获得手牌时，将其改为【毒】并随机分发给场上其他玩家；<br>④当其他角色因【毒】的效果流失体力时，你增加一点体力上限并回复一点体力值。",
}

local mhusi = fk.CreateTriggerSkill{
  name = "diy_mhusi",
  anim_type = "special",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    return target == player and #player:getTableMark("@"..self.name) < 5
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@"..self.name)
    local all = {"diy_husi_jin","diy_husi_mu","diy_husi_shui","diy_husi_huo","diy_husi_tu"}
    for _, m in ipairs(mark) do
      table.removeOne(all,m)
    end
    if #all > 0 then
      local s = table.random(all)
      table.insertIfNeed(mark,s)
      room:setPlayerMark(player,"@"..self.name,mark)
      room:doIndicate(player.id,table.map(room:getOtherPlayers(player),Util.IdMapper))
      if s == "diy_husi_mu" then
        for _, p in ipairs(room:getOtherPlayers(player)) do
          if not p.dead then
            room:loseHp(p,1,self.name)
            if not p.dead then
              local card = room:getCardsFromPileByRule("es__poison",1)
              if #card > 0 then
                room:obtainCard(p,card,true,fk.ReasonPrey,player.id,self.name)
              end
            end
          end
        end
      elseif s == "diy_husi_tu" then
        for _, p in ipairs(room:getOtherPlayers(player)) do
          if not p.dead then
            room:loseHp(p,1,self.name)
          end
        end
        local buff = room:getBanner("@[:]diy_mhusi") or {}
        table.insertIfNeed(buff,"diy_mhusi_tu")
        room:setBanner("@[:]diy_mhusi",buff)
      elseif s == "diy_husi_huo" then
        if not player.dead and player:isWounded() then
          
          room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
        end
        local buff = room:getBanner("@[:]diy_mhusi") or {}
        table.insertIfNeed(buff,"diy_mhusi_huo")
        room:setBanner("@[:]diy_mhusi",buff)
      elseif s == "diy_husi_shui" then
          for _, p in ipairs(room.alive_players) do
            if not p.dead and p.hp > 1 then
              local n = p.hp - 1
              room:loseHp(p,n,self.name)
              if not p.dead then
                room:changeShield(p,n)
              end
            end
          end
          local buff = room:getBanner("@[:]diy_mhusi") or {}
          table.insertIfNeed(buff,"diy_mhusi_shui")
          room:setBanner("@[:]diy_mhusi",buff)
      elseif s == "diy_husi_jin" then
          for _, p in ipairs(room.alive_players) do
            if not p.dead and p:isWounded() then
              room:recover({
                who = p,
                num = p:getLostHp(),
                skillName = self.name
              })
            end
          end
          local buff = room:getBanner("@[:]diy_mhusi") or {}
          table.insertIfNeed(buff,"diy_mhusi_jin")
          room:setBanner("@[:]diy_mhusi",buff)
      end
      if #mark >= 5 then
        room.logic:trigger("fk.diy_mhusi", player)
      end
    end
  end,

}
local mhusi_delay = fk.CreateTriggerSkill{
  name = "#diy_mhusi_delay",
  anim_type = "negative",
  priority = 0.023,
  events = {fk.DamageInflicted,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if not  (player.room:getBanner("@[:]diy_mhusi") and type(player.room:getBanner("@[:]diy_mhusi")) == "table") then return end
    return target == player and not player.dead
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = room:getBanner("@[:]diy_mhusi") or {}
    if event == fk.DamageInflicted then
      if table.contains(mark,"diy_mhusi_huo") then
        data.damage = data.damage*2
      end
      if table.contains(mark,"diy_mhusi_tu") then
        data.damage = data.damage - 1
      end
      if table.contains(mark,"diy_mhusi_jin") then
        local n = data.damage
        data.damage = 0
        room:loseHp(player,n,mhusi.name)
        return true
      end
    elseif table.contains(mark,"diy_mhusi_jin") then
      room:changeMaxHp(player,1)
      if not player.dead and player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          skillName = self.name
        })
      end
      if not player.dead then
        player:drawCards(5,mhusi.name)
      end
    end
  end,
}
mhusi.permanent_skill = true
mhusi_delay.permanent_skill = true
mhusi:addRelatedSkill(mhusi_delay)
Fk:loadTranslationTable{
  ["diy_mhusi"] = "狐死",
  [ "#diy_mhusi_delay"] = "狐死",
  ["@[:]diy_mhusi"] = "狐死",
  ["@diy_mhusi"] = "",
  [":diy_mhusi"] = "持恒技，当你进入濒死状态时，你随机触发以下一个未触发过的效果："..
  "<br><font color='green'>木肝</font>，所有其他角色失去一点体力并获得一张【毒】。"..
  "<br><font color='burlywood'>土脾</font>，所有其他角色失去一点体力，本局游戏全场受到的伤害-1。"..
  "<br><font color='red'>火心</font>，你回复一点体力，本局游戏全场受到的伤害翻倍。"..
  "<br><font color='blue'>水肾</font>，所有角色失去体力至1点并获得失去体力数护甲，本局游戏每名角色回合结束时增加一点体力上限并回复一点体力，然后摸五张牌。"..
  "<br><font color='yellow'>金肺</font>，所有角色回满体力，本局游戏全场伤害视为体力流失。",
  ["diy_mhusi_huo"] = "<font color='red'>火心</font>",
  [":diy_mhusi_huo"] = "全场受到的伤害翻倍。",
  ["diy_husi_huo"] = "<font color='red'>火</font>",
  ["diy_mhusi_shui"] = "<font color='blue'>水肾</font>",
  [":diy_mhusi_shui"] = "每名角色回合结束时增加一点体力上限并回复一点体力，然后摸五张牌。",
  ["diy_husi_shui"] = "<font color='blue'>水</font>",
  ["diy_mhusi_jin"] = "<font color='yellow'>金肺</font>",
  [":diy_mhusi_jin"] = "全场伤害视为体力流失。",
  ["diy_husi_jin"] = "<font color='yellow'>金</font>",
  ["diy_mhusi_mu"] = "<font color='green'>木肝</font>",
  ["diy_husi_mu"] = "<font color='green'>木</font>",
  ["diy_mhusi_tu"] = "<font color='burlywood'>土脾</font>",
  [":diy_mhusi_tu"] = "全场受到的伤害-1",
  ["diy_husi_tu"] = "<font color='burlywood'>土</font>",
}
local mhusheng = fk.CreateTriggerSkill{
  name = "diy_mhusheng",
  anim_type = "special",
  frequency = Skill.Wake,
  events = {"fk.diy_mhusi"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function (self, event, target, player, data)
    return #player:getTableMark("@diy_mhusi") >= 5
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:delay(2000)
    room:gameOver(player.role)
  end,
}
Fk:loadTranslationTable{
  ["diy_mhusheng"] = "狐生",
  [":diy_mhusheng"] = "觉醒技，当你触发〖狐死〗的全部五种效果后，你胜利。",
}
local huxiangli10 = General(extension, "diy_qun__menghuxiangli", "moe",4)
table.insertIfNeed(lord_generals,huxiangli10.name)
huxiangli10:addSkill(hushi)
huxiangli10:addSkill(mhusi)
huxiangli10:addSkill(mhusheng)
Fk:loadTranslationTable{
  ["diy_qun__menghuxiangli"] = "狐火旺",
  [ "#diy_qun__menghuxiangli"] = "",
  ["designer:diy_qun__menghuxiangli"] = "狐湘狸",
}

local kaidu = fk.CreateActiveSkill{
  name = "diy_kaidu",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "每回合限三次，弃置一张牌并选择一名与上次选择不同的角色，令其猜测你弃置牌的花色",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 3
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
end,
  target_filter = function(self, to_select, selected, selected_cards)
      if #selected == 0 and to_select ~= Self then
        local mark = Self:getTableMark(self.name.."-turn")
        return not table.contains(mark,to_select)
      end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:setPlayerMark(player,self.name.."-turn",{target.id})
    local card = Fk:getCardById(effect.cards[1])
    room:moveCardTo(card,Card.DiscardPile,nil,fk.ReasonDiscard,self.name,"",false,player.id)
    if player.dead or target.dead then return end
    local suits = {"log_heart","log_diamond","log_spade","log_club"}
    local g = room:askForChoice(target,suits,self.name,"猜测 "..pg(player).." 弃置牌的花色，若猜对，你摸俩张牌，猜错，你受到对方的两点伤害")
    local suit = card:getSuitString(true)
    player:showCards(effect.cards)
    if suit == g then
      room:setCardEmotion(effect.cards[1],"judgegood")
      if not target.dead then
        target:drawCards(2,self.name)
      end
    else
      room:setCardEmotion(effect.cards[1],"judgebad")
      if not target.dead then
        room:doIndicate(player.id,{target.id})
        room:damage{
          from = player,
          to = target,
          damage = 2,
          damageType = fk.NormalDamage,
          skillName = self.name,
        }
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_kaidu"] = "开赌",
  [":diy_kaidu"] = "每回合限三次，出牌阶段，你可以弃置一张牌并选择一名与上次选择不同的其他角色，令其猜测你弃置牌的花色：<br>若猜对，其摸两张牌；<br>若猜错，其受到来自你的两点伤害。",
}

local hujue = fk.CreateTriggerSkill{
  name = "diy_hujue",
  events = {fk.TargetConfirming,fk.Damaged},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.TargetConfirming then
        return data.from and data.from ~= player.id and target == player 
      else
        return target == player and data.from and not data.from.dead and data.from ~= player
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.TargetConfirming then
      return player.room:askForSkillInvoke(player,self.name,nil,"狐绝：你可以进行一次判定，若为黑，"..data.card:toLogString().."对你无效")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      local judge = {
        who = target,
        reason = self.name,
        pattern = ".|.|club,spade",
      }
      room:judge(judge)
      if judge.card.color == Card.Black  then
        room:doIndicate(player.id,{data.from})
        AimGroup:cancelTarget(data, player.id)
      end
    else
      room:doIndicate(player.id,{data.from.id})
      room:damage{
        from = player,
        to = data.from,
        damage = data.damage,
        damageType = data.damageType,
        skillName = self.name,
      }
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_hujue"] = "狐绝",
  [":diy_hujue"] = "锁定技，当你成为其他角色使用牌的目标时，你可以进行一次判定，若判定结果为黑，该牌对你无效；当你受到来自其他角色造成的伤害后，你对其造成同样的伤害。",
}


local huchou = fk.CreateActiveSkill{
  name = "diy_huchou",
  anim_type = "control",
  min_card_num = 1,
  min_target_num = 1,
  prompt = "出牌阶段限一次，你可以将任意张手牌置于等量名其他角色武将牌上各一张，称为“狐臭”（已有则替换之）。",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected < (#Fk:currentRoom().alive_players - 1)  and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
end,
  target_filter = function(self, to_select, selected, selected_cards)
      if #selected_cards > 0 and #selected < #selected_cards then
        return to_select ~= Self.id
      end
  end,
  feasible = function (self, selected, selected_cards)
    return #selected == #selected_cards
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tars = {}
    for _, pid in ipairs(effect.tos) do
      table.insertIfNeed(tars,room:getPlayerById(pid))
    end
    local ucards = player.room:askForYiji(player,effect.cards,tars, self.name,#effect.cards,#effect.cards,"为每名目标放置一张“狐臭”，若其已有则替换之",nil,true,1)
    if ucards then
      for pid,cards in pairs(ucards) do
        local p = room:getPlayerById(tonumber(pid))
        local yes = false
        if not p.dead then
          if #p:getPile("diy_huchou") > 0 then
            room:moveCardTo(p:getPile("diy_huchou"),Card.DiscardPile,nil,fk.ReasonJustMove,self.name)
          end
          if not p.dead then
            p:addToPile("diy_huchou",cards,true,self.name)
            yes = true
          end
        end
        if not yes then
          room:moveCardTo(cards,Card.DiscardPile,nil,fk.ReasonJustMove,self.name)
        end
      end
    end
  end,
}
local huchou_prohibit = fk.CreateProhibitSkill{
  name = "#diy_huchou_prohibit",
  prohibit_use = function(self, player, card)
    if player.phase == Player.NotActive and player:getPile("diy_huchou") and #player:getPile("diy_huchou") > 0 then
      local suits = {}
      for _, cid in ipairs(player:getPile("diy_huchou")) do
        table.insertIfNeed(suits,Fk:getCardById(cid).suit)
      end
      return  card and table.contains(suits, card.suit)
    end
  end,
  prohibit_response = function(self, player, card)
    if player.phase == Player.NotActive and player:getPile("diy_huchou") and #player:getPile("diy_huchou") > 0 then
      local suits = {}
      for _, cid in ipairs(player:getPile("diy_huchou")) do
        table.insertIfNeed(suits,Fk:getCardById(cid).suit)
      end
      return  card and table.contains(suits, card.suit)
    end
  end,
}
local huchou_trigger = fk.CreateTriggerSkill{
  name = "#diy_huchou_trigger",
  events = {fk.TurnStart},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return target ~= player and #target:getPile("diy_huchou") > 0
    end
  end,
  on_cost = function (self, event, target, player, data)
      return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{target.id})
    if not target:isKongcheng() then
      room:throwCard(table.random(target:getCardIds("h"),1),huchou.name,target,player)
    end
    if not target.dead then
      room:loseHp(target,1,huchou.name)
    end
  end,
}
huchou:addRelatedSkill(huchou_trigger)
huchou:addRelatedSkill(huchou_prohibit)
Fk:loadTranslationTable{
  ["diy_huchou"] = "狐臭",
  [":diy_huchou"] = "出牌阶段限一次，你可以将任意张手牌置于等量名其他角色武将牌上各一张，称为“狐臭”（若对方已有“狐臭”，则先置入弃牌堆）。"..
  "<br>①有狐臭的角色于其回合外不能使用或打出“狐臭”中包含花色的牌。"..
  "<br>②有“狐臭”的其他角色回合开始时，你弃置其一张牌并令其失去一点体力。",
  ["#diy_huchou_trigger"] = "狐臭",
  ["#diy_huchou_prohibit"] = "狐臭",

}
local huxiangli11 = General(extension, "diy_qun__qinhuxiangli", "qin",4)
table.insertIfNeed(lord_generals,huxiangli11.name)
huxiangli11:addSkill(kaidu)
huxiangli11:addSkill(hujue)
huxiangli11:addSkill(huchou)
Fk:loadTranslationTable{
  ["diy_qun__qinhuxiangli"] = "狐杰瑞",
  [ "#diy_qun__qinhuxiangli"] = "",
  ["designer:diy_qun__qinhuxiangli"] = "狐湘狸",
}

local huyao = fk.CreateTriggerSkill{
  name = "diy_huyao",
  events = {fk.TurnStart},
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and player.id > 0 and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 and target.hp > player.hp
  end,
  on_cost = function (self, event, target, player, data)
      return player.room:askForSkillInvoke(player,self.name,nil,"你可以附身"..Pg(target).."直到本回合结束")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{target.id})
    local mark = target.tag[self.name] or {}
    table.insertIfNeed(mark,player.id)
    target.tag[self.name] = mark
    room:setPlayerMark(target,"diy_huyao-turn",1)
    room:setPlayerMark(target,"@@diy_huyao",1)
    player:control(target)
  end,
  refresh_events = {fk.TurnEnd,fk.EventAcquireSkill,fk.AfterCardsMove,fk.AfterPlayerRevived},
  can_refresh = function (self, event, target, player, data)
    if not (player.tag[self.name] and #player.tag[self.name] > 0) then return end
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to and move.toArea == Card.PlayerHand and move.to == player.id then
          return true
        end
      end
    elseif event == fk.EventAcquireSkill then
      return target == player and data:isPlayerSkill(target) and string.sub(data.name, 1,1) ~= "#" and  data.visible 
    elseif event == fk.TurnEnd then
      return true
    elseif event == fk.AfterPlayerRevived then
      return target == player 
    end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.TurnEnd then
      player:control(player)
      player.tag[self.name] = nil
      return 
    end
    local mark = player.tag[self.name] or {}
    if event == fk.AfterCardsMove then
      local n = 0
      for _, move in ipairs(data) do
        if move.to and move.toArea == Card.PlayerHand and move.to == player.id then
          n = n + #move.moveInfo
        end
      end
      if n > 0 then
        for _, pid in ipairs(mark) do
          local p = player.room:getPlayerById(pid)
          if not p.dead then
            p:drawCards(n,self.name)
          end
        end
      end
    elseif event == fk.EventAcquireSkill then
      for _, pid in ipairs(mark) do
        local p = player.room:getPlayerById(pid)
        if not p.dead then
          player.room:handleAddLoseSkills(p,data.name)
        end
      end
    elseif event == fk.AfterPlayerRevived then
      player.room:setPlayerMark(player,"diy_huyao-turn",1)
    end
  end,
}
local huyao_mod = fk.CreateTargetModSkill{
  name = "#diy_huyao_mod",
  bypass_times = function(self, player, skill, scope)
    return player:getMark("diy_huyao-turn") > 0
  end,
  bypass_distances = function(self, player, skill, scope)
    return player:getMark("diy_huyao-turn") > 0
  end,
}
huyao:addRelatedSkill(huyao_mod)
huyao.permanent_skill = true
huyao_mod.permanent_skill = true
Fk:loadTranslationTable{
  ["diy_huyao"] = "狐妖",
  ["@@diy_huyao"] = "被附身过",
  [":diy_huyao"] = "持恒技，每轮限一次，当一名体力大于你的其他角色回合开始时，你可以对其进行附身直到回合结束：<br>附身期间该角色的所有行动由你控制，被附身的角色使用牌无距离次数限制，且当被附身的角色获得技能或手牌时，附身来源获得同样的技能摸等量张牌。",
  ["#diy_huyao_mod"] = "狐妖",


}
local shoumeng = fk.CreateTriggerSkill{
  name = "diy_shoumeng",
  events = {fk.DamageInflicted,fk.Damage},
  anim_type = "special",
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self) and data.from and data.from:getMark("@@diy_huyao") == 0
    elseif event == fk.Damage then
      return player:hasSkill(self) and target and target:getMark("@@diy_huyao") > 0 
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.DamageInflicted then
      return true
    elseif event == fk.Damage then
      local ch1 = "你与"..Pg(target).."各回复一点体力"
      local ch2 = "你与"..Pg(target).."各摸一张牌"
      local all = {ch1,ch2}
      local can = {}
      if player:isWounded() or (not target.dead and target:isWounded()) then
        table.insertIfNeed(can,ch1)
      end
      table.insertIfNeed(can,ch2)
      if #can < 2 then
        self.cost_data = ch2
        return true
      else
        local ch = player.room:askForChoice(player,can,self.name,"选择一项执行",false,all)
        if ch then
          self.cost_data = ch
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player,self.name,"defensive")
      data.damage = data.damage - 1
    elseif event == fk.Damage then
      room:doIndicate(player.id,{target.id})
      local ch1 = "你与"..Pg(target).."各回复一点体力"
      local ch2 = "你与"..Pg(target).."各摸一张牌"
      if self.cost_data == ch1 then
        room:notifySkillInvoked(player,self.name,"support")
        if player:isWounded() then
          room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
        end
        if not target.dead and target:isWounded() then
          room:recover({
            who = target,
            num = 1,
            recoverBy = player,
            skillName = self.name
          })
        end
      else
        room:notifySkillInvoked(player,self.name,"drawcard")
        if not player.dead then
          player:drawCards(1,self.name)
        end
        if not target.dead then
          target:drawCards(1,self.name)
        end
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_shoumeng"] = "守梦",
  [":diy_shoumeng"] = "锁定技，未被〖狐妖〗附身过的角色对你造成的伤害-1；被〖狐妖〗附身过的角色造成伤害后，你选择与其各回复一点体力或各摸一张牌。",


}
local huxiangli12 = General(extension, "diy_qun__waihuxiangli", "th_k__outside",3,3,General.Female)
table.insertIfNeed(lord_generals,huxiangli12.name)
huxiangli12:addSkill(huyao)
huxiangli12:addSkill(shoumeng)
Fk:loadTranslationTable{
  ["diy_qun__waihuxiangli"] = "狐妖梦",
  [ "#diy_qun__waihuxiangli"] = "",
  ["designer:diy_qun__waihuxiangli"] = "狐湘狸",
}


-- 根据关键词获得技能
local doJiren = function (player, event)
  local room = player.room
  if player.dead then return end
  if player:isWounded() then
    room:recover { num = 1, skillName = "diy_humi", who = player , recoverBy = player}
  end
  if player.dead then return end
  local skillName = "diy_humi"
  local skillPatterns = {
    [fk.Damage] = "斩击射刹破截铁",[fk.Deathed] = "断情连灵化魂境",[fk.AfterCardsMove] = "极锦渔铸善夺史",
    [fk.CardUseFinished] = "神统定乱使舞裂",[fk.EnterDying] = "死续封殇萍翼游",[fk.Damaged] = "狐害兽缘藏试怒"
  }
  local pattern = skillPatterns[event]
  local str = {}
  for i = 1, pattern:len() do
    local s = pattern[i]
    table.insert(str, s)
  end
  local skills = {}
  for _, general_name in pairs(room.general_pile) do
    local general = Fk.generals[general_name]
    for _, skill_name in ipairs(general:getSkillNameList()) do
      local skill = Fk.skills[skill_name]
      if not player:hasSkill(skill,true) and table.find(str, function(s) return string.find(Fk:translate(skill.name), s) end)
       then
        table.insert(skills, skill.name)
      end
    end
  end
  if #skills == 0 then return end
  local choice = room:askForChoice(player, table.random(skills,4), skillName, nil, true)
  room:handleAddLoseSkills(player, choice)
end

local function updataJirenMark(player, event)
  local room = player.room
  local mark = {}
  if event ~= fk.EventLoseSkill then
    local removed = player:getTableMark("diy_humi_removed")
    for i = 1, 6 do
      local m = "diy_humi_"..i
      if not table.contains(removed, m) then
        table.insert(mark, m)
      end
    end
  end
  room:setPlayerMark(player, "@[:]diy_humi", #mark > 0 and mark or 0)
end

local humi = fk.CreateTriggerSkill{
  name = "diy_humi",
  frequency = Skill.Compulsory,
  events = {fk.Damage, fk.Deathed, fk.AfterCardsMove, fk.CardUseFinished, fk.EnterDying,fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    local room = player.room
    if not player:hasSkill(self) then return false end
    local event_list = {fk.Damage, fk.Deathed, fk.AfterCardsMove, fk.CardUseFinished, fk.EnterDying,fk.Damaged}
    local choice = "diy_humi_"..table.indexOf(event_list, event)
    if table.contains(player:getTableMark("diy_humi_removed"), choice) then return false end
    if event == fk.Damage then
      return player == target and not data.to.dead and not data.to:isNude()
    elseif event == fk.Deathed then
      return data.damage and data.damage.from and data.damage.from == player
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).type == Card.TypeEquip and room:getCardArea(info.cardId) == Card.DiscardPile then
              for _, p in ipairs(room.alive_players) do
                if not p.dead and #p:getCardIds("e") > 0 then
                  return true
                end
              end
            end
          end
        end
      end
    elseif event == fk.CardUseFinished then
      return player == target and data.card:isCommonTrick()  
    elseif event == fk.EnterDying then
      return player == target
    elseif event == fk.Damaged then
     if target == player and not player:isKongcheng() then
      for _, cid in ipairs(player:getCardIds("h")) do
        if player:canUse(Fk:getCardById(cid)) then
          return true
        end
      end
     end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local event_list = {fk.Damage, fk.Deathed, fk.AfterCardsMove, fk.CardUseFinished, fk.EnterDying,fk.Damaged}
    local mark = player:getTableMark("diy_humi_removed")
    local choice = "diy_humi_"..table.indexOf(event_list, event)
    table.insertIfNeed(mark, choice)
    room:setPlayerMark(player, "diy_humi_removed", mark)
    updataJirenMark(player, event)
    if event == fk.Damage then
      local card = room:askForCardsChosen(player,data.to,1,1,"he",self.name)
      if #card > 0 then
        room:obtainCard(player,card,true,fk.ReasonPrey,player.id,self.name)
      end
    elseif event == fk.Deathed then
      player:drawCards(2, self.name)
    elseif event == fk.AfterCardsMove then
      local tars = {}
      for _, p in ipairs(room.alive_players) do
        if not p.dead and #p:getCardIds("e") > 0 then
          table.insertIfNeed(tars,p.id)
        end
      end
      if #tars > 0 then
        local tos = room:askForChoosePlayers(player,tars, 1, 1, "选择获得场上的一件装备", self.name, false)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          local card = room:askForCardsChosen(player,to,1,1,"e",self.name)
          if #card > 0 then
            room:obtainCard(player,card,true,fk.ReasonPrey,player.id,self.name)
          end
        end
      end
    elseif event == fk.CardUseFinished then
      local name = Fk:cloneCard(data.card.name,data.card.suit,data.card.number)
      name.skillName = self.name
      local use ={
        from = player.id,
        tos = data.tos,
        card = name,
        extraUse = true
      }
      room:useCard(use)
    elseif event == fk.EnterDying then
      if player:isWounded() then
        room:recover { num = 1 - player.hp, skillName = self.name, who = player , recoverBy = player}
      end
    elseif event == fk.Damaged then
      U.askForUseRealCard(room,player,player:getCardIds("h"),".",self.name,nil,nil,false,false)
    end
    if not player.dead then
      doJiren (player, event)
    end
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player and data == self    
  end,
  on_refresh = function (self, event, target, player, data)
    updataJirenMark(player, event)
  end,
}
local huxiangli13 = General(extension, "diy_qun__chaoyuanhuxiangli", "chaoyuan",5,5,General.Female)
table.insertIfNeed(lord_generals,huxiangli13.name)
huxiangli13:addSkill(humi)
Fk:loadTranslationTable{
  ["diy_qun__chaoyuanhuxiangli"] = "狐小恋",
  [ "#diy_qun__chaoyuanhuxiangli"] = "",
  ["designer:diy_qun__chaoyuanhuxiangli"] = "狐湘狸",
}
Fk:loadTranslationTable{


  ["diy_humi"] = "狐秘",
  [":diy_humi"] = "锁定技，每项限一次，以下时机你需执行一次对应的效果，然后回复一点体力并从技能名包含关键字的四个技能中获得一个。"..
  "<br>①对一名角色造成伤害后，获得其一张牌，获得“斩击射刹破截铁”；"..
  "<br>②击杀一名角色后，摸两张牌，获得“断情连灵化魂境”；"..
  "<br>③装备牌被弃置时，获得场上一张装备，获得“极锦渔铸善夺史”；"..
  "<br>④使用普通锦囊牌后，再次使用一次此牌，获得“神统定乱使舞裂”；"..
  "<br>⑤进入濒死状态时，回复体力至一点，获得“死续封殇萍翼游”；"..
  "<br>⑥受到伤害后，使用一张手牌，获得“狐害兽缘藏试怒”。",

  ["@[:]diy_humi"] = "<font color='pink'>狐秘</font>",
  ["diy_humi_1"] = "造伤",
  [":diy_humi_1"] = "①对一名角色造成伤害后，获得其一张牌，获得“斩击射刹破截铁”",
  ["diy_humi_2"] = "击杀",
  [":diy_humi_2"] = "②击杀一名角色后，摸两张牌，获得“断情连灵化魂境”",
  ["diy_humi_3"] = "装备",
  [":diy_humi_3"] = "③装备牌被弃置时，获得场上一张装备，获得“极锦渔铸善夺史”",
  ["diy_humi_4"] = "锦囊",
  [":diy_humi_4"] = "④使用普通锦囊牌后，再次使用一次此牌，获得“神统定乱使舞裂”",
  ["diy_humi_5"] = "濒死",
  [":diy_humi_5"] = "⑤进入濒死状态时，回复体力至一点，获得“死续封殇萍翼游”",
  ["diy_humi_6"] = "受伤",
  [":diy_humi_6"] = "⑥受到伤害后，使用一张手牌，获得“狐害兽缘藏试怒”",
}

local huxiang = fk.CreateTriggerSkill{
  name = "diy_huxiang",
  events = {fk.DamageCaused,fk.DamageInflicted,fk.TurnEnd},
  anim_type = "special",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if (player:hasSkill(self) and table.contains({player.general,player.deputyGeneral},"diy_qun__renhuxiangli")) then
      if event == fk.DamageCaused then
        return target == player and data.card and data.card.type ~= Card.TypeEquip
      elseif event == fk.DamageInflicted then
        return target == player
      elseif event == fk.TurnEnd then
        local lord,rebel,renegade = {},{},{}
        for _, p in ipairs(player.room.alive_players) do
          if p.role == "lord" or p.role == "loyalist" then
            table.insertIfNeed(lord,p.id)
          elseif p.role == "rebel" then
            table.insertIfNeed(rebel,p.id)
          else
            table.insertIfNeed(renegade,p.id)
          end
        end
        local n = #renegade
        if #lord > 0 then
          n = n + 1
        end
        if #rebel > 0 then
          n = n + 1
        end
        return n == 2
      end
    end
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player,self.name,"support")
      room:changeShield(player,1)
      room:changeMaxHp(player,1)
      if player.dead or not player:isWounded() then
        return 
      end
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif event == fk.DamageCaused then
      room:notifySkillInvoked(player,self.name,"support")
      room:doIndicate(player.id,{data.to.id})
      if data.card.type == Card.TypeBasic then
        if data.to:isWounded() then
          room:recover({
            who = data.to,
            num = 1,
            recoverBy = player,
            skillName = self.name
          })
        end
        return true
      elseif data.card.type == Card.TypeTrick then
        room:changeMaxHp(data.to,1)
      end
    else
      room:notifySkillInvoked(player,self.name,"negative")
      room:killPlayer({who = player.id})
    end
  end,
  refresh_events = {fk.EventAcquireSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player  and data == self and player.room:isGameMode("role_mode") and player.role ~= "lord"and player:hasSkill(self,true) and table.contains({player.general,player.deputyGeneral},"diy_qun__renhuxiangli") 
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:notifySkillInvoked(player,self.name,"negative")
    player.role = "renegade"
    player.room:broadcastProperty(player,"role")
  end,
}
Fk:loadTranslationTable{
  ["diy_huxiang"] = "狐想",
  [":diy_huxiang"] = "共鸣技，①你的锦囊牌造成伤害时令目标增加一点体力上限，你的基本牌造成伤害时令目标回复一点体力并防止此伤害；②你受到伤害时护盾、体力上限及体力各加1；③若你不为“主公”，你获得此技能时身份改为“内奸”；④每个回合结束时，若此时场上仅剩俩个阵营，你死亡。",


}

local rhuxiang = fk.CreateFilterSkill{
  name = "diy_rhuxiang",
  frequency = Skill.Compulsory,
  card_filter = function(self, to_select, player)
    return player:hasSkill(self) and table.contains({Card.TypeBasic,Card.TypeTrick},to_select.type) and table.contains(player.player_cards[Player.Hand],to_select.id)
  end,
  view_as = function(self, to_select)
    if to_select.type == Card.TypeBasic then
      local card = Fk:cloneCard("fire__slash", to_select.suit, to_select.number)
      card.skillName = self.name
      return card
    elseif to_select.type == Card.TypeTrick then
      local card = Fk:cloneCard("archery_attack",to_select.suit, to_select.number)
      card.skillName = self.name
      return card
    end
  end,
}
local rhuxiang_targetmod = fk.CreateTargetModSkill{
  name = "#diy_rhuxiang_targetmod",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope, card, to)
    return player:hasSkill(rhuxiang) 
  end,
  bypass_distances = function(self, player, skill, card, to)
    return player:hasSkill(rhuxiang) 
  end,
}
rhuxiang:addRelatedSkill(rhuxiang_targetmod)
Fk:loadTranslationTable{
  ["diy_rhuxiang"] = "狐相",
  [":diy_rhuxiang"] = "锁定技，你手中的基本牌视为火【杀】，手中的锦囊牌视为【万箭齐发】；你使用牌无距离次数限制。",

}

local huxiang3 = fk.CreateTriggerSkill{
  name = "diy_huxiang3",
  events = {fk.AfterSkillEffect,fk.CardUseFinished},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player ~= target and not (player.room.current and player.room.current == player) and not target.dead then
      if event == fk.AfterSkillEffect then
        if target:getMark("@diy_huxiang3_skill") >= 6 then
          player.room:doIndicate(player.id,{target.id})
          player.room:setPlayerMark(target,"@diy_huxiang3_skill",target:getMark("@diy_huxiang3_skill")%6)
          return true
        end
      elseif event == fk.CardUseFinished then
        if target:getMark("@diy_huxiang3_use") >= 6 then
          player.room:doIndicate(player.id,{target.id})
          player.room:setPlayerMark(target,"@diy_huxiang3_use",target:getMark("@diy_huxiang3_use")%6)
          return true
        end
      end
    end
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterSkillEffect then
      local mark = target:getTableMark("@[:]diy_huxiang3-turn")
      local skills = {}
      for _, s in ipairs(target.player_skills) do
        if s.visible and not s.name:startsWith("#") and not s.name:endsWith("&") and s.permanent_skill ~= true and not s:isEquipmentSkill(target) then
          table.insertIfNeed(skills,s.name)
        end
      end
      if #skills > 0 then
        table.insertIfNeed(mark,table.random(skills))
        room:setPlayerMark(target,"@[:]diy_huxiang3-turn",mark)
      end
    elseif event == fk.CardUseFinished then
      room:loseHp(target,2,self.name)
    end
  end,
  refresh_events = {fk.AfterSkillEffect,fk.CardUseFinished},
  can_refresh =function (self, event, target, player, data)
      if target == player and not player.dead then
        for _, p in ipairs(player.room:getOtherPlayers(target)) do
          if p:hasSkill(self,true) and not (player.room.current and player.room.current == p) and (event == fk.CardUseFinished or (not data:isEquipmentSkill(target) and not data.name:endsWith("&") and target:hasSkill(data,true))) then
            return true
          end
        end
      end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.AfterSkillEffect then
      player.room:addPlayerMark(player,"@diy_huxiang3_skill",1)
    elseif event == fk.CardUseFinished then
      player.room:addPlayerMark(player,"@diy_huxiang3_use",1)
    end
  end,
}
local huxiang3_invalidity = fk.CreateInvaliditySkill {
name = "#diy_huxiang3_invalidity",
invalidity_func = function(self, from, skill)
return table.contains(from:getTableMark("@[:]diy_huxiang3-turn"),skill.name)
end
}
huxiang3.permanent_skill = true
huxiang3_invalidity.permanent_skill = true
huxiang3:addRelatedSkill(huxiang3_invalidity)
Fk:loadTranslationTable{
  ["@[:]diy_huxiang3-turn"] = "技能失效",
  ["diy_huxiang3"] = "狐降",
  ["@diy_huxiang3_skill"] = "发动技能",
  ["@diy_huxiang3_use"] = "使用牌",
  [":diy_huxiang3"] = "持恒技，你的回合外，其他角色每发动6次技能后，令其随机一个技能本回合失效；其他角色每使用6张牌后，令其失去两点体力。",

}

local huxiangli13 = General(extension, "diy_qun__renhuxiangli", "th_k__human",3,3,General.Female)
table.insertIfNeed(lord_generals,huxiangli13.name)
huxiangli13:addSkill(huxiang)
huxiangli13:addSkill(rhuxiang)
huxiangli13:addSkill(huxiang3)
Fk:loadTranslationTable{
  ["diy_qun__renhuxiangli"] = "狐柒夜",
  [ "#diy_qun__renhuxiangli"] = "",
  ["designer:diy_qun__renhuxiangli"] = "狐湘狸",
}

local huce = fk.CreateTriggerSkill{
  name = "diy_huce",
  events = {fk.AfterCardsMove, fk.EventPhaseChanging},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.EventPhaseChanging then
      return target == player and (data.to == Player.Draw or data.to == Player.Judge)
    elseif player:getHandcardNum() ~= 4 then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        elseif move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.EventPhaseChanging then
      room:notifySkillInvoked(player, self.name, "negative")
      return true
    else
      local num = 4 - player:getHandcardNum()
      if num > 0 then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:drawCards(num, self.name)
      elseif num < 0 then
        room:notifySkillInvoked(player, self.name, "negative")
        room:askForDiscard(player, -num, -num, false, self.name, false)
      end
    end
  end,
}
local huce_view = fk.CreateFilterSkill{
  name = "#diy_huce_view",
  frequency = Skill.Compulsory,
  card_filter = function(self, to_select, player)
    return player:hasSkill(huce) and table.contains({Card.TypeBasic,Card.TypeTrick},to_select.type) and table.contains(player.player_cards[Player.Hand],to_select.id)
  end,
  view_as = function(self, to_select)
    if to_select.type == Card.TypeBasic then
      local card = Fk:cloneCard("fire__slash", to_select.suit, to_select.number)
      card.skillName = huce.name
      return card
    elseif to_select.type == Card.TypeTrick then
      local card = Fk:cloneCard("duel", to_select.suit, to_select.number)
      card.skillName = huce.name
      return card
    end
  end,
}
huce:addRelatedSkill(huce_view)
Fk:loadTranslationTable{
  ["diy_huce"] = "狐测",
  ["#diy_huce_view"] = "狐测",
  [":diy_huce"] = "锁定技，你跳过摸牌阶段与弃牌阶段；你的手牌数发生变化后，你将手牌调整至4张；你手中的锦囊牌视为【决斗】，基本牌视为火【杀】。",

}
local hudong = fk.CreateTriggerSkill{
  name = "diy_hudong",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect,fk.TargetSpecified},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return  end
    if event == fk.TargetSpecified then
      return  target ~= player  and (data.card.trueName == "slash" or data.card.type == Card.TypeTrick) and data.firstTarget and 
      table.contains(AimGroup:getAllTargets(data.tos), player.id)
    elseif event == fk.DamageInflicted then
      return  data.from ~= player and not data.from.dead
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|heart,diamond",
      }
      room:judge(judge)
      if player.dead then return end
      if judge.card.color == Card.Red then
        table.insertIfNeed(data.nullifiedTargets, player.id)
        room:doIndicate(player.id,{target.id})
      end
    elseif event == fk.DamageInflicted then
      room:doIndicate(player.id,{data.from.id})
      room:loseHp(data.from,data.damage,self.name)
    end
  end,

}
Fk:loadTranslationTable{
  ["diy_hudong"] = "狐动",
  [":diy_hudong"] = "锁定技，其他角色使用【杀】或锦囊牌指定你为目标后，你进行一次判定，若判定结果为<font color = 'red'>红</font>，该牌对你无效。",

}
local heti = fk.CreateTriggerSkill{
  name = "diy_heti",
  events = {fk.Deathed},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self,false,true) and table.contains({player.general,player.deputyGeneral},"diy_qun__ziranhuxiangli")
  end,
  on_cost = function(self, event, target, player, data)
    local tars = {}
    for _, p in ipairs(player.room.alive_players) do
      if p.role ~= "lord" then
        table.insertIfNeed(tars,p.id)
      end
    end
    if #tars > 0 then
      local tar = player.room:askForChoosePlayers(player,tars,1,1,"选择一名非主公角色，令其获得你的所有体力上限与技能",self.name,true)
      if #tar > 0 then
        self.cost_data = tar[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    if player.maxHp > 0 then
      room:changeMaxHp(tar,player.maxHp)
    end
    local skills = {}
    for _, s in ipairs(player.player_skills) do
      if s.visible and not s.name:startsWith("#") and not s.name:endsWith("&") and s.permanent_skill ~= true and not s:isEquipmentSkill(target) then
        table.insertIfNeed(skills,s.name)
      end
    end
    if #skills > 0 then
      room:handleAddLoseSkills(tar,table.concat(skills,"|"))
    end
    if not tar.dead  and tar.role ~= "lord" and pvp(room) then
      tar.role = player.role == "lord" and "loyalist" or player.role
      room:broadcastProperty(tar,"role")
      room:setPlayerProperty(tar, "role_shown", true)
      
      room.logic:trigger(fk.GameOverJudge, player,data)
    end
  end,

}
Fk:loadTranslationTable{
  ["diy_heti"] = "合体",
  [":diy_heti"] = "共鸣技，你死亡后，你可令一名不为主公的其他角色获得你的所有体力上限与技能，然后其将身份变更为与你相同。"..
  "<br><font color = 'grey'><small>变更身份仅限于场上不存在人机的情况。",

}
local huxiangli14 = General(extension, "diy_qun__ziranhuxiangli", "ziran",4)
table.insertIfNeed(lord_generals,huxiangli14.name)
huxiangli14:addSkill(huce)
huxiangli14:addSkill(hudong)
huxiangli14:addSkill(heti)
Fk:loadTranslationTable{
  ["diy_qun__ziranhuxiangli"] = "狐达四号",
  [ "#diy_qun__ziranhuxiangli"] = "",
  ["designer:diy_qun__ziranhuxiangli"] = "狐湘狸",
}

local humei = fk.CreateTriggerSkill{
  name = "diy_humei",
  events = {fk.GameStart,fk.Damaged,fk.Damage},
  anim_type = "control",
  priority = 1.5,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.GameStart then
      return true
    elseif event == fk.Damaged then
      return target == player and data.from  and #data.from:getTableMark("@[:]diy_humei") > 0 
    elseif event == fk.Damage then
      return target == player and data.to and #data.to:getTableMark("@[:]diy_humei") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      room:doIndicate(player.id,table.map(room.alive_players,Util.IdMapper))
      for _, p in ipairs(room.alive_players) do
        if not p.dead then
          local mark = p:getTableMark("@[:]diy_humei")
          local skills = {}
          for _, general in ipairs(Fk:getAllGenerals()) do
            for _, skill in ipairs(general:getSkillNameList()) do
              if string.find(Fk:translate(":"..skill, "zh_CN"), "【杀】") and not p:hasSkill(skill, true) and not table.contains(mark,skill) then
                table.insertIfNeed(skills, skill)
              end
            end
          end
          if #skills > 0 then
            skills = table.random(skills,3)
            table.insertTableIfNeed(mark,skills)
            room:setPlayerMark(p,"@[:]diy_humei",mark)
            room:handleAddLoseSkills(p,table.concat(skills,"|"), nil, true, false)
          end
        end
      end
    elseif event == fk.Damaged then
      room:doIndicate(player.id,{data.from.id})
      room:loseHp(data.from,1,self.name)
      if data.from.dead then
        return false
      end
      local mark = data.from:getTableMark("@[:]diy_humei")
      local s = table.random(mark)
      table.removeOne(mark,s)
      room:setPlayerMark(data.from,"@[:]diy_humei",#mark > 0 and mark or 0)
      player.room:handleAddLoseSkills(data.from,"-"..s)
    elseif event == fk.Damage then
      room:doIndicate(player.id,{data.to.id})
      local mark = data.to:getTableMark("@[:]diy_humei")
          local skills = {}
          for _, general in ipairs(Fk:getAllGenerals()) do
            for _, skill in ipairs(general:getSkillNameList()) do
              if string.find(Fk:translate(":"..skill, "zh_CN"), "【杀】") and not data.to:hasSkill(skill, true) and not table.contains(mark,skill) then
                table.insertIfNeed(skills, skill)
              end
            end
          end
          if #skills > 0 then
            skills = table.random(skills,1)
            table.insertTableIfNeed(mark,skills)
            room:setPlayerMark(data.to,"@[:]diy_humei",mark)
            room:handleAddLoseSkills(data.to,table.concat(skills,"|"), nil, true, false)
          end
    end
  end,
  refresh_events = {fk.BuryVictim},
  can_refresh = function (self, event, target, player, data)
    return target == player and #player:getTableMark("@[:]diy_humei") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player,"-"..table.concat(player:getTableMark("@[:]diy_humei"),"|-"))
    player.room:setPlayerMark(player,"@[:]diy_humei",0)
  end,
}
Fk:loadTranslationTable{
  ["diy_humei"] = "狐魅",
  ["@[:]diy_humei"] = "<font color = '#E800E8'>狐魅</font>",
  [":diy_humei"] = "游戏开始时，你令全场获得3枚<font color = '#E800E8'>狐魅</font>；你对有<font color = '#E800E8'>狐魅</font>的角色造成伤害后，令其获得1枚<font color = '#E800E8'>狐魅</font>；你受到拥有<font color = '#E800E8'>狐魅</font>角色造成的伤害后，令其失去1点体力，然后其随机失去1枚<font color = '#E800E8'>狐魅</font>。"..
  "<br><small>获得<font color = '#E800E8'>狐魅</font>时随机获得一个技能描述包含【杀】的技能直到失去该<font color = '#E800E8'>狐魅</font>。",
}
local yhuying = fk.CreateTriggerSkill{
  name = "diy_yhuying",
  refresh_events = {fk.DamageCaused},
  anim_type = "negative",
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and (target == player or data.to == player ) and not (data.extra_data and data.extra_data.diy_yhuying)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.Damage,true)
    if not e then
      return
    end
    local logic = room.logic
    local damageStruct = data
    data.extra_data = data.extra_data or {}
    data.extra_data.diy_yhuying = true
    local stages = {
      { fk.DamageCaused, "from" },
      { fk.DamageInflicted, "to" },
    }

    for _, struct in ipairs(stages) do
      local event, player = table.unpack(struct)
      if logic:trigger(event, damageStruct[player], damageStruct) or damageStruct.damage < 1 then
        damageStruct.damage = 1
      end
      assert(damageStruct.to:isInstanceOf(ServerPlayer))
    end
  
    damageStruct.damage = 1

    if damageStruct.to.dead then
      if e then
        e:shutdown()
      end
      return false
    end
  
    damageStruct.dealtRecorderId = room.logic.specific_events_id[GameEvent.Damage]
    room.logic.specific_events_id[GameEvent.Damage] = room.logic.specific_events_id[GameEvent.Damage] + 1
  
    if damageStruct.card and damageStruct.damage > 0 then
      local parentUseData = logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if parentUseData then
        local cardUseEvent = parentUseData.data[1]
        cardUseEvent.damageDealt = cardUseEvent.damageDealt or {}
        cardUseEvent.damageDealt[damageStruct.to.id] = (cardUseEvent.damageDealt[damageStruct.to.id] or 0) + damageStruct.damage
      end
    end
    if event == fk.DamageCaused then
        room:notifySkillInvoked(player,self.name,"offensie")
    else
        room:notifySkillInvoked(player,self.name,"defensive")
    end
    if not room:changeHp(
      damageStruct.to,
      -damageStruct.damage,
      "damage",
      damageStruct.skillName,
      damageStruct) then
      logic:breakEvent(false)
    end
  
  
    stages = {
      {fk.Damage, "from"},
      {fk.Damaged, "to"},
    }
  
    for _, struct in ipairs(stages) do
      local event, player = table.unpack(struct)
      logic:trigger(event, damageStruct[player], damageStruct)
    end

    logic:trigger(fk.DamageFinished, damageStruct.to, damageStruct)

    if damageStruct.chain_table and #damageStruct.chain_table > 0 then
      damageStruct.chain_table = table.filter(damageStruct.chain_table, function(p)
        return p:isAlive() and p.chained
    end)
    for _, p in ipairs(damageStruct.chain_table) do
      room:sendLog{
        type = "#ChainDamage",
        from = p.id
      }

      local dmg = {
        from = damageStruct.from,
        to = p,
        damage = damageStruct.damage,
        damageType = damageStruct.damageType,
        card = damageStruct.card,
        skillName = damageStruct.skillName,
        chain = true,
      }

      room:damage(dmg)
    end
  end

    if e then
      e:shutdown()
    end
  end,

}
Fk:loadTranslationTable{
  ["diy_yhuying"] = "狐影",
  [":diy_yhuying"] = "持恒技，你造成或受到的伤害无法被抵消且恒为1。",

}

yhuying.permanent_skill = true
local huxiangli15 = General(extension, "diy_qun__yaohuxiangli", "th_k__yokai",4,4,General.Female)
table.insertIfNeed(lord_generals,huxiangli15.name)
huxiangli15:addSkill(humei)
huxiangli15:addSkill(yhuying)
Fk:loadTranslationTable{
  ["diy_qun__yaohuxiangli"] = "狐魅儿",
  [ "#diy_qun__yaohuxiangli"] = "",
  ["designer:diy_qun__yaohuxiangli"] = "狐湘狸",
}


-- 在脸上显示角色武将名（若有副将，改为显示位置）
-- 传入值：角色ID
Fk:addQmlMark{
  name = "hname",
  qml_path = "",
  how_to_show = function(_, value)
    if type(value) == "string" then value = tonumber(value) end --- 实际访问的时候这里会出string
    if not value or type(value) ~= "number" then return " " end
    local player = Fk:currentRoom():getPlayerById(value)
    if (not player) or (not player.general) or (player.general == "") then return " " end
    local ret = player.general
    return Fk:translate(ret)
  end,
}


local lianji = fk.CreateTriggerSkill{
  name = "diy_lianji",
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and table.contains({player.general,player.deputyGeneral},"diy_qun__zihuxiangli")
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tars = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if p:getMark("@[hname]diy_lianji") == 0 then
        table.insertIfNeed(tars,p.id)
      end
    end
    if #tars > 1 then
      local tar = room:askForChoosePlayers(player,tars,2,2,"你可以将俩名角色“链接”起来，“链接”中的角色受到伤害后另一方也会受到同样的伤害",self.name,true)
      if #tar > 1 then
        self.cost_data = tar
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(room:getPlayerById(self.cost_data[1]),"@[hname]diy_lianji",self.cost_data[2])
    room:setPlayerMark(room:getPlayerById(self.cost_data[2]),"@[hname]diy_lianji",self.cost_data[1])
  end,
  refresh_events = {fk.BuryVictim},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@[hname]diy_lianji") ~= 0 and player.room:getPlayerById(player:getMark("@[hname]diy_lianji")) and not player.room:getPlayerById(player:getMark("@[hname]diy_lianji")).dead
  end,
  on_refresh =function (self, event, target, player, data)
    player.room:setPlayerMark(player.room:getPlayerById(player:getMark("@[hname]diy_lianji")),"@[hname]diy_lianji",0)
    player.room:setPlayerMark(player,"@[hname]diy_lianji",0)
  end,
}
local lianji_delay = fk.CreateTriggerSkill{
  name = "#diy_lianji_delay",
  events = {fk.Damaged},
  priority = 0.9,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@[hname]diy_lianji") ~= 0 and data.skillName ~= lianji.name and player.room:getPlayerById(player:getMark("@[hname]diy_lianji")) and not player.room:getPlayerById(player:getMark("@[hname]diy_lianji")).dead
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{player:getMark("@[hname]diy_lianji")})
    room:damage{
      from = data.from,
      to = room:getPlayerById(player:getMark("@[hname]diy_lianji")),
      damage = data.damage,
      damageType = data.damageType,
      skillName = lianji.name,
    }
  end,
}
lianji:addRelatedSkill(lianji_delay)
Fk:loadTranslationTable{
  ["diy_lianji"] = "联机",
  ["#diy_lianji_delay"] = "联机",
  ["@[hname]diy_lianji"] = "<font color = '#2894FF'>链接</font>",
  [":diy_lianji"] = "共鸣技，每轮开始时，你可以将俩名未被“链接”的其他角色“链接”起来，“链接”中的角色受到伤害后另一方也会受到同样的伤害。",

}

local jingbi = fk.CreateActiveSkill{
  name = "diy_jingbi",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "你可以令一名角色本轮无法使用打出牌，且发动的所有技能取消之。",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryRound) == 0 
  end,
  card_filter = function() return false end,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data)
    return Fk:currentRoom():getPlayerById(to_select):getMark("@@diy_jingbi-round") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:doIndicate(player.id,effect.tos)
    room:setPlayerMark(room:getPlayerById(effect.tos[1]),"@@diy_jingbi-round",1)
  end,
}
local jingbi_delay = fk.CreateTriggerSkill{
  name = "#diy_jingbi_delay",
  refresh_events = {fk.SkillEffect},
  mute = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_jingbi-round") > 0 and player:hasSkill(data.name,true,true) and  data.name ~= self and  not data:isEquipmentSkill(target)  and
    not data.name:endsWith("&") 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect,true)
    
    room:notifySkillInvoked(target,"diy_jingbi","negative")
    if e then
      e:shutdown()
    end
  end,
}
local jingbi_prohibit = fk.CreateProhibitSkill{
  name = "#diy_jingbi_prohibit",
  prohibit_use = function(self, player, card)
      return player:getMark("@@diy_jingbi-round") > 0
  end,
  prohibit_response = function(self, player, card)
      return player:getMark("@@diy_jingbi-round") > 0
  end,
}
local jingbi_in = fk.CreateInvaliditySkill {
  name = "#diy_jingbi_in",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@diy_jingbi-round") > 0  and skill:isPlayerSkill(from)
  end
}
jingbi:addRelatedSkill(jingbi_delay)
jingbi:addRelatedSkill(jingbi_prohibit)
jingbi:addRelatedSkill(jingbi_in)
Fk:loadTranslationTable{
  ["diy_jingbi"] = "禁闭",
  ["#diy_jingbi_delay"] = "禁闭",
  ["#diy_jingbi_prohibit"] = "禁闭",
  ["@@diy_jingbi-round"] = "<font color = '#930000'>禁闭</font>",
  ["#diy_jingbi_in"] = "禁闭",
  [":diy_jingbi"] = "每轮限一次，出牌阶段，你可令一名角色本轮无法使用或打出牌，且其发动技能时取消之。",

}

local shenli = fk.CreateTriggerSkill{
  name = "diy_shenli",
  events = {fk.RoundStart},
  mute = true,
  priority = 1.2,
  can_trigger = function(self, event, target, player, data)
    return player.seat == 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local all = {"diy_shenli_1",}
    local n = math.random(1,5)
    room:setBanner("@[:]diy_shenli","diy_shenli_"..n)
    if n > 1 and n < 5 then
      room:doBroadcastNotify("ShowToast", "本轮<font color = '#o2F78E'>神力</font>为 "..Fk:translate("diy_shenli_"..n).."："..Fk:translate(":diy_shenli_"..n))
    else
      room:doBroadcastNotify("ShowToast", "本轮<font color = '#o2F78E'>神力</font>为 "..Fk:translate("diy_shenli_"..n).."")
    end
    for _, p in ipairs(room.alive_players) do
      room:setPlayerMark(p,"diy_shenli4",0)
    end
    if n == 2 then
      for _, p in ipairs(room.alive_players) do
        if not p.dead then
          room:changeMaxHp(p,2)
        end
      end
    elseif n == 3 then
      for _, p in ipairs(room.alive_players) do
        if not p.dead then
          room:loseHp(p,2)
        end
      end
    elseif n == 4 then
      for _, p in ipairs(room.alive_players) do
        room:setPlayerMark(p,"diy_shenli4",1)
      end
    end
  end,
  refresh_events = {fk.BuryVictim},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@[hname]diy_lianji") ~= 0 and player.room:getPlayerById(player:getMark("@[hname]diy_lianji")) and not player.room:getPlayerById(player:getMark("@[hname]diy_lianji")).dead
  end,
  on_refresh =function (self, event, target, player, data)
    player.room:setPlayerMark(player,"@[hname]diy_lianji",0)
    player.room:setPlayerMark(player.room:getPlayerById(player:getMark("@[hname]diy_lianji")),"@[hname]diy_lianji",0)
  end,
}

local shenli_delay = fk.CreateTriggerSkill{
  name = "#diy_shenli_delay",
  events = {fk.AfterSkillEffect,fk.CardUseFinished,fk.TurnStart},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    if not player.room:getBanner("@[:]diy_shenli") or target ~= player or player.dead then return end
      if event == fk.AfterSkillEffect then
        if player.room:getBanner("@[:]diy_shenli") == "diy_shenli_1" and target:getMark("diy_shenli1_skill") >= 5 then
          player.room:setPlayerMark(target,"diy_shenli1_skill",target:getMark("diy_shenli1_skill")%5)
          return true
        end
      elseif event == fk.CardUseFinished then
        if player.room:getBanner("@[:]diy_shenli") == "diy_shenli_1" and target:getMark("diy_shenli1_use") >= 5 then
          player.room:setPlayerMark(target,"diy_shenli1_use",target:getMark("diy_shenli1_use")%5)
          return true
        end
      elseif event == fk.TurnStart then
          return player.room:getBanner("@[:]diy_shenli") == "diy_shenli_5"
      end
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterSkillEffect then
      room:addPlayerMark(player,"@diy_shenli1",1)
    elseif event == fk.CardUseFinished then
      room:addPlayerMark(player,"@diy_shenli2",1)
    elseif event == fk.TurnStart then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|club,spade",
      }
      room:judge(judge)
      if player.dead then return end
      if judge.card.color == Card.Black then
        room:damage{
          to = target,
          damage = 2,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
    end
  end,
  refresh_events = {fk.AfterSkillEffect,fk.CardUseFinished},
  can_refresh =function (self, event, target, player, data)
    if target ~= player or player.dead or not (player.room:getBanner("@[:]diy_shenli") and player.room:getBanner("@[:]diy_shenli") == "diy_shenli_1") then return end
    if event == fk.AfterSkillEffect then
      return   not data:isEquipmentSkill(target) and not data.name:endsWith("&") and target:hasSkill(data,true)
    else
      return true
    end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.AfterSkillEffect then
      player.room:addPlayerMark(player,"diy_shenli1_skill",1)
    elseif event == fk.CardUseFinished then
      player.room:addPlayerMark(player,"diy_shenli1_use",1)
    end
  end,
}
local shenli_delay2 = fk.CreateTriggerSkill{
  name = "#diy_shenli_delay2",
  events = {fk.DamageCaused,fk.DamageInflicted},
  anim_type = "offensive",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      return target == player and player:getMark("@diy_shenli2") > 0
    elseif event == fk.DamageInflicted then
      return target == player and player:getMark("@diy_shenli1") > 0
    end
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      data.damage = data.damage + player:getMark("@diy_shenli2")
    elseif event == fk.DamageInflicted then
      data.damage = data.damage + player:getMark("@diy_shenli2")
    end
  end,
}
local shenli_mod = fk.CreateTargetModSkill{
  name = "#diy_shenli_mod",
  bypass_times = function(self, player, skill, scope)
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p:getMark("diy_shenli4") > 0 then
        return true
      end
    end
  end,
  bypass_distances = function(self, player, skill, scope)
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p:getMark("diy_shenli4") > 0 then
        return true
      end
    end
  end,
}
shenli:addRelatedSkill(shenli_delay)
shenli:addRelatedSkill(shenli_mod)
shenli:addRelatedSkill(shenli_delay2)
Fk:loadTranslationTable{
  ["diy_shenli"] = "神力",
  ["#diy_shenli_delay"] = "神力",
  ["#diy_shenli_delay2"] = "神力",
  ["#diy_shenli_mod"] = "神力",
  ["@diy_shenli1"] = "受伤",
  ["@diy_shenli2"] = "加伤",
  ["@[:]diy_shenli"] = "<font color = '#28FF28'>本轮神力</font>",
  ["diy_shenli_1"] = "<font color='yellow'>金</font>",
  [":diy_shenli_1"] = "所有角色每累计发动5次技能后受伤数值永久+1，每累计使用5张牌后造成伤害数值永久+1。",
  ["diy_shenli_2"] = "<font color='green'>木</font>",
  [":diy_shenli_2"] = "所有角色各增加两点体力上限。",
  ["diy_shenli_3"] = "<font color='blue'>水</font>",
  [":diy_shenli_3"] = "所有角色各失去两点体力。",
  ["diy_shenli_4"] = "<font color='red'>火</font>",
  [":diy_shenli_4"] = "所有角色使用牌无距离次数限制。",
  ["diy_shenli_5"] = "<font color='burlywood'>土</font>",
  [":diy_shenli_5"] = "所有角色回合开始时进行一次判定，若为黑则其受到两点雷电伤害。",
  [":diy_shenli"] = "<font color = '#28FF28'>此技能永久生效</font>；"..
  "<br>每轮开始时，随机从以下5项效果中抽取一个替换场上的<font color = '#28FF28'>神力效果</font>："..
  "<br><font color='yellow'>金</font>：所有角色每累计发动5次技能后受伤数值永久+1，每累计使用5张牌后造成伤害数值永久+1。"..
  "<br><font color='green'>木</font>：所有角色各增加两点体力上限。"..
  "<br><font color='blue'>水</font>：所有角色各失去两点体力。"..
  "<br><font color='red'>火</font>：所有角色使用牌无距离次数限制。"..
  "<br><font color='burlywood'>土</font>：所有角色回合开始时进行一次判定，若为黑则其受到两点雷电伤害。",

}
local huxiangli16 = General(extension, "diy_qun__zihuxiangli", "th_k__nature",4,4,General.Female)
table.insertIfNeed(lord_generals,huxiangli16.name)
huxiangli16:addSkill(lianji)
huxiangli16:addSkill(jingbi)
huxiangli16:addSkill(shenli)
Fk:loadTranslationTable{
  ["diy_qun__zihuxiangli"] = "狐神",
  [ "#diy_qun__zihuxiangli"] = "",
  ["designer:diy_qun__zihuxiangli"] = "狐湘狸",
}


local jiuwei = fk.CreateTriggerSkill{
  name = "diy_jiuwei",
  events = {fk.GameStart},
  frequency = Skill.Limited,
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@@diy_jiuwei",1)
  end,
}
local jiuwei_delay = fk.CreateTriggerSkill{
  name = "#diy_jiuwei_delay",
  events = {fk.EnterDying,fk.BeforeMaxHpChanged},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_jiuwei") > 0
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.EnterDying then 
      room:setPlayerMark(player,"@@diy_jiuwei",0)
      if player.maxHp < 9 then
        player.maxHp = 9
        room:broadcastProperty(player,"maxHp")
        room.logic:trigger("fk.diy_sichun_hpchanged", player)
      end
      if player.dead then return end
      if player:isWounded() then
        room:recover({
          who = player,
          num = math.min(9,player.maxHp) - player.hp,
          recoverBy = player,
          skillName = self.name
        })
      end
    elseif event == fk.BeforeMaxHpChanged then
      return true
    end
  end,
}
jiuwei:addRelatedSkill(jiuwei_delay)
Fk:loadTranslationTable{
  ["diy_jiuwei"] = "九尾",
  ["#diy_jiuwei_delay"] = "九尾",
  ["@@diy_jiuwei"] = "<font color = '#F00078'>九尾</font>",
  [":diy_jiuwei"] = "限定技，游戏开始时你获得<font color = '#F00078'>九尾</font>标记。<br>●拥有<font color = '#F00078'>九尾</font>标记的角色体力上限不会因其他技能改变，且当其进入濒死状态时，移除<font color = '#F00078'>九尾</font>标记并将体力上限与体力恢复至9点。",
}

local huai = fk.CreateTriggerSkill{
  name = "diy_huai",
  events = {fk.RoundStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end, 
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tars = {}
    for _, p in ipairs(room.alive_players) do
      if p:getMark("@@diy_huai") == 0 then
        table.insert(tars,p.id)
      end
    end
    if #tars == 0 then return false end
      local tar = room:askForChoosePlayers(player,tars,1,1,"令一名角色获得“狐爱”标记。",self.name,true)
      if #tar > 0 then
        self.cost_data = tar[1]
        return true
      end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(room:getPlayerById(self.cost_data),"@@diy_huai",player.id)
  end,
}
local huai_delay = fk.CreateTriggerSkill{
  name = "#diy_huai_delay",
  events = {fk.EnterDying,fk.DamageCaused,fk.DamageInflicted,fk.HpRecover},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_huai") ~= 0
  end, 
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local pid = player:getMark("@@diy_huai")
    room:setPlayerMark(player,"@@diy_huai",0)
    if event == fk.EnterDying then 
      if player.maxHp > 0 then
        room:recover({
          who = player,
          num = 1 - player.hp,
          skillName = self.name
        })
      end
      room:setPlayerMark(player,"@@diy_huai-turn",1)
    elseif event == fk.DamageCaused then
      local tars = table.map(room.alive_players,function(p) return p.id end)
      room:doIndicate(player.id,tars)
      room:sortPlayersByAction(tars)
      for _, pid in ipairs(tars) do
        local p = room:getPlayerById(pid)
        if not p.dead then
          room:damage({
            to = p,
            damage = 1,
            skillName = self.name,
          })
        end
      end
    elseif event == fk.DamageInflicted then
      local tars = table.map(room.alive_players,function(p) return p.id end)
      room:doIndicate(player.id,tars)
      room:sortPlayersByAction(tars)
      for _, pid in ipairs(tars) do
        local p = room:getPlayerById(pid)
        if not p.dead then
          room:loseHp(p,1,self.name)
        end
      end
    elseif event == fk.HpRecover then
      room:changeMaxHp(player,1)
      if room:getPlayerById(pid) and not room:getPlayerById(pid).dead and room:getPlayerById(pid):isWounded() then
        room:doIndicate(player.id,{pid})
        room:recover({
          who = room:getPlayerById(pid),
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end,
}
local huai_delay2 = fk.CreateTriggerSkill{
  name = "#diy_huai_delay2",
  events = {fk.PreHpLost,fk.DamageInflicted},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_huai-turn") > 0
  end, 
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function (self, event, target, player, data)
    return true
  end,
}
huai:addRelatedSkill(huai_delay)
huai:addRelatedSkill(huai_delay2)
Fk:loadTranslationTable{
  ["diy_huai"] = "狐爱",
  ["#diy_huai_delay"] = "狐爱",
  ["#diy_huai_delay2"] = "狐爱",
  ["@@diy_huai"] = "<font color = '#FF00FF'>狐爱</font>",
  ["@@diy_huai-turn"] = "<font color = '#FF00FF'>狐爱 免伤</font>",
  [":diy_huai"] = "每轮开始时，你可令一名没有<font color = '#FF00FF'>狐爱</font>的角色获得<font color = '#FF00FF'>狐爱</font>标记。"..
  "<br>●拥有<font color = '#FF00FF'>狐爱</font>标记的角色在以下时机移除<font color = '#FF00FF'>狐爱</font>标记并触发对应效果："..
  "<br>1,造成伤害后，令全场所有角色各受到1点伤害。"..
  "<br>2,受到伤害后，令全场所有角色各失去1点体力。"..
  "<br>3,回复体力后，增加1点体力上限并令你回复1点体力。"..
  "<br>4,进入濒死状态时，将体力值恢复至1点，然后防止其本回合受到的所有伤害与体力流失。",
}

local huxiangli17 = General(extension, "diy_qun__shanhuxiangli", "th_k__mountain",3,3,General.Female)
table.insertIfNeed(lord_generals,huxiangli17.name)
huxiangli17:addSkill(jiuwei)
huxiangli17:addSkill(huai)
Fk:loadTranslationTable{
  ["diy_qun__shanhuxiangli"] = "狐杏",
  [ "#diy_qun__shanhuxiangli"] = "",
  ["designer:diy_qun__shanhuxiangli"] = "狐湘狸",
}

local huxian2 = fk.CreateActiveSkill{
  name = "diy_huxian2",
  anim_type = "control",
  prompt = "令一名角色进行判定，并根据判定结果执行效果",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 
  end,
  target_num = 1,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local judge = {
      who = target,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade  then
      if target.dead then return end
      room:loseHp(target,2,self.name)
      if target.dead then return end
      room:setPlayerMark(target,"@@diy_huxian2-turn",1)
    elseif judge.card.suit == Card.Club  then
      if target.dead then return end
      room:changeMaxHp(target,-1)
      if target.dead then return end
      room:setPlayerMark(target,"@@diy_huxian2_phase",1)
    elseif judge.card.suit == Card.Heart  then
      if target.dead then return end
      room:changeMaxHp(target,1)
      if not target.dead and target:isWounded() then
        room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = self.name
        })
      end
      if player.dead or player == target then return end
      local tars = {}
      local skills = {}
      for _, s in ipairs(target.player_skills) do
        if s:isPlayerSkill(target) and s.visible and not player:hasSkill(s.name,true) then
          table.insert(skills, s.name)
        end
      end
      if #skills > 0 then
        room:askForCustomDialog(player, nil,
      "packages/utility/qml/ChooseSkillBox.qml", {
        skills, 0, 1, "选择"..Pg(target).."的一个技能获得"
      })
      if  player.reply_ready then
        local choice = json.decode(player.client_reply) 
        room:handleAddLoseSkills(player,table.concat(choice, "|"), nil)
      end
      end
    elseif judge.card.suit == Card.Diamond  then
      if not target.dead and not target:isKongcheng() then
        room:throwCard(target:getCardIds("h"),self.name,target,player)
      end
      if not player.dead then
        player:drawCards(3,self.name)
      end
    end
  end,
}
local huxian2_delay = fk.CreateTriggerSkill{
  name = "#diy_huxian2_delay",
  anim_type = "negative",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@diy_huxian2_phase") > 0 and data.to == Player.Play
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player,"@@diy_huxian2_phase",0)
    player:skip(Player.Play)
    return true
  end,
}
local huxian2_in = fk.CreateInvaliditySkill {
  name = "#diy_huxian2_in",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@diy_huxian2-turn") > 0  and skill:isPlayerSkill(from)
  end
}
huxian2:addRelatedSkill(huxian2_delay)
huxian2:addRelatedSkill(huxian2_in)
Fk:loadTranslationTable{
  ["diy_huxian2"] = "狐仙",
  ["#diy_huxian2_delay"] = "狐仙",
  ["#diy_huxian2_in"] = "狐仙",
  ["@@diy_huxian2-turn"] = "技能失效",
  ["@@diy_huxian2_phase"] = "跳过阶段",
  [":diy_huxian2"] = "每回合限一次，出牌阶段，你可令一名角色进行判定，若为："..
  "<br>♠，其失去2点体力且本回合所有技能失效。"..
  "<br>♣，其减少1点体力上限并跳过下个出牌阶段。"..
  "<br><font color = 'red'>♥</font>，其增加1点体力上限并回复1点体力，然后你获得其一个技能。"..
  "<br><font color = 'red'>♦</font>，其弃置所有手牌，你摸3张牌。",
}


local huying2 = fk.CreateTriggerSkill{
  name = "diy_huying2",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to ~= player and not data.to.dead and data.to:getMark("@@diy_huying2") == 0
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(data.to,"@@diy_huying2",1)
  end,
}
local huying2_delay = fk.CreateTriggerSkill{
  name = "#diy_huying2_delay",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@diy_huying2") > 0 and player.room.current == player and not player.dead then
      if event == fk.CardUsing then
        local room = player.room
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if use_event == nil then return false end
        local x = target:getMark("diy_huying2-turn")
        if x == 0 then
          room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
            local use = e.data[1]
            if use.from == target.id then
              x = e.id
              room:setPlayerMark(target, "diy_huying2-turn", x)
              return true
            end
          end, Player.HistoryPhase)
        end
        return x == use_event.id
      else
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      data.tos = {}
    else
      room:damage({
        to = target,
        damage = 2, 
        skillName = self.name,
      })
    end
  end,
}

huying2:addRelatedSkill(huying2_delay)
Fk:loadTranslationTable{
  ["diy_huying2"] = "狐影",
  ["#diy_huying2_delay"] = "狐影",
  ["@@diy_huying2"] = "<font color = '#8600FF'>狐影</font>",
  [":diy_huying2"] = "锁定技，你对其他角色造成伤害时，令其获得<font color = '#8600FF'>狐影</font>标记。"..
  "<br>●有<font color = '#8600FF'>狐影</font>标记的角色于其回合内使用的第一张牌无效，且其回合结束时受到2点伤害。",
}
local huxian = fk.CreateTriggerSkill{
  name = "diy_huxian",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from ~= player.id and
      (data.card.type == Card.TypeTrick or data.card.trueName == "slash")
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      local judge = {
        who = target,
        reason = self.name,
        pattern = ".",
      }
    room:judge(judge)
    if player.dead then return end
    if judge.card.color == Card.Black  then
      if room:getCardArea(data.card.id) == Card.Processing then
        room:obtainCard(player,data.card,true,fk.ReasonJustMove,player.id,self.name)
      end
    else
      room:doIndicate(player.id, {data.from})
      table.insertIfNeed(data.nullifiedTargets, player.id)
      if not room:getPlayerById(data.from).dead then
        room:damage({
          from = player,
          to = room:getPlayerById(data.from),
          damage = 2, 
          skillName = self.name,
        })
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["diy_huxian"] = "狐羡",
  [":diy_huxian"] = "锁定技，当你成为其他角色使用的【杀】或锦囊牌目标后，你判定，若为：<br><font color = 'red'>红</font>，此牌对你无效且你对使用者造成2点伤害；<br>黑，你获得此牌。",
}
local huxiangli18 = General(extension, "diy_qun__huanhuxiangli", "huan",4)
table.insertIfNeed(lord_generals,huxiangli18.name)
huxiangli18:addSkill(huxian2)
huxiangli18:addSkill(huying2)
huxiangli18:addSkill(huxian)
Fk:loadTranslationTable{
  ["diy_qun__huanhuxiangli"] = "狐羡仙",
  [ "#diy_qun__huanhuxiangli"] = "",
  ["designer:diy_qun__huanhuxiangli"] = "狐湘狸",
}
return extension